Is it possible to add a resource (user / facility) to an serviceappointment?
Here's my record to which I want to add resources:
var serviceAppointment = this.organizationService.Retrieve(
"serviceappointment",
serviceActivityGuid,
new ColumnSet(true));
I have a list of resources:
{
"ListOfResourceIds": [
{
"partyid": "9CDC2C51-6417-4550-A0FE-D825EE75D333"
},
{
"partyid": "9CDC2C51-6417-4550-A0FE-D825EE75D044"
}
]
}
How would I add these resources to ServiceAppointment above?
I suspect that after adding them, I would call:
organizationService.Update(serviceAppointment);
Resources are of the type ActivityParty (SystemUser). To update the service appointment, get the corresponding system user ids of the resources:
var serviceAppointment = organizationService.Retrieve(
"serviceappointment",
serviceActivityGuid,
new ColumnSet(true));
var updateServiceAppointment = new Entity("serviceappointment")
{
Id = serviceAppointment.Id
};
updateServiceAppointment["resources"] = new[]
{
new ActivityParty()
{
PartyId = new CrmEntityReference("systemuser", correspondingSystemUserId)
}
};
organizationService.Update(updateServiceAppointment);
Related
I try add payment method to my project where customer can buy product from other user. But i have problem because when i use it:
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = "{{PRICE_ID}}",
Quantity = 1,
},
},
Mode = "payment",
SuccessUrl = "https://example.com/success",
CancelUrl = "https://example.com/cancel",
PaymentIntentData = new SessionPaymentIntentDataOptions
{
ApplicationFeeAmount = 123,
},
};
var requestOptions = new RequestOptions
{
StripeAccount = "{{CONNECTED_ACCOUNT_ID}}",
};
var service = new SessionService();
Session session = service.Create(options, requestOptions);
PRICE_ID can't be price's on my main stripe account and i must create product and price on the connected account.
In the case of creating a product on the main account, I do it like this:
var options = new ProductCreateOptions
{
Id = ProductId.ToString(),
Name = "Product_name",
DefaultPriceData = new ProductDefaultPriceDataOptions
{
UnitAmount = price,
Currency = "pln"
},
Expand = new List<string> { "default_price" },
};
_productService.Create(options);
How create product and price on the connected account with my api?
The Stripe API has a Stripe-Account header where you can pass in the ID of one of your connected accounts to make the call as that account. In C# that would look like this:
{
Id = ProductId.ToString(),
Name = "Product_name",
DefaultPriceData = new ProductDefaultPriceDataOptions
{
UnitAmount = price,
Currency = "pln"
},
Expand = new List<string> { "default_price" },
StripeAccount = "acct_123456789",
};
_productService.Create(options);
I am using stripe for payments.
When I create the SessionCreateOptions object I add the CustomerId and ProductId for later usage in my Webhook.
var options = new SessionCreateOptions
{
PaymentMethodTypes = new List<string> {
"card",
},
CustomerEmail = buyer.Email,
LineItems = new List<SessionLineItemOptions> {
new SessionLineItemOptions {
Name = packages.First().Name,
Description = packages.First().Description,
Amount = (long)(totalAmount * 100),
Currency = "eur",
Quantity = 1,
},
},
SuccessUrl = appSettings.RedirectHost.Url + "/Checkouts/Show/success?session_id={CHECKOUT_SESSION_ID}",
CancelUrl = appSettings.RedirectHost.Url + "/Checkouts/Show/failed",
Metadata = new Dictionary<String, String>()
{
{ "CustomerId", buyer.Id.ToString()},
{ "ProductId", packages.First().Id.ToString()}
},
};
After a successful payment the webhook gets called and retrieves to object with customer data, price and other values, but the metadata dictionary is empty.
You are retrieving the PaymentIntent that was created by the CheckoutSession, but you're setting the metadata on the CheckoutSession itself.
There are two options, depending on where you want to store and retrieve the metadata. You can retrieve the CheckoutSession directly [0], or you change your code to set the metadata on the PaymentIntent when creating the CheckoutSession, via payment_intent_data.metadata [1].
[0] https://stripe.com/docs/api/checkout/sessions/retrieve
[1] https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata
Since we were forced to upgrade our mongo installation, we're receiving an error during some aggregation function calls:
MongoDB.Driver.MongoCommandException: "Command 'aggregate' failed: The
'cursor' option is required, except for aggregate with the explain
argument (response: { "ok" : 0.0, "errmsg" : "The 'cursor' option is
required, except for aggregate with the explain argument", "code" : 9,
"codeName" : "FailedToParse" })"
BsonArray arr = BsonSerializer.Deserialize<BsonArray>("[{ \"$match\" : { \"Param1\" : \"VAL\" } }, { \"$unwind\" : \"$Entries\" }, { \"$match\" : { \"PARAM\" : \"VALUE\" } }]");
var pipeline = arr.Select(x => x.AsBsonDocument).ToList();
// AggregateArgs aArgs = new AggregateArgs { Pipeline = bsonList };
var cursor = collection.Aggregate(pipeline).ResultDocuments;
I already figured out, that we have to manually add cursor configuration to the BsonDocument - but we weren't able to figure out, how the query should be configured.
Is there any work around for this exception (without changing drivers)?
give this a shot:
var cursor = collection.Aggregate<BsonDocument>(pipeline);
var results = cursor.ToList(); //just get a list of documents and be done with it
while (cursor.MoveNext()) // or iterate over cursor
{
foreach (var doc in cursor.Current.ToArray())
{
//access your documents here
}
}
You have extra brace in the end of query string
was finally able to fix it, by building the command by myself:
var cmd = new CommandDocument()
{
{"aggregate", "collection_name" },
{"pipeline", arr},
{"cursor", BsonDocument.Parse("{}") }
};
var res = db.RunCommand(cmd);
This is what worked in my situation (mongocshardriver v1.9.0-rc0, mongodb server 4.4.0); OutputMode = AggregateOutputMode.Cursor in the AggregateArgs.
public IEnumerable<BsonDocument> Run(MongoCollection<Item> items)
{
var priceRange = new BsonDocument(
"$subtract",
new BsonArray
{
"$Price",
new BsonDocument(
"$mod",
new BsonArray{"$Price", 100})
});
var grouping = new BsonDocument(
"$group",
new BsonDocument
{
{"_id", priceRange},
{"count", new BsonDocument("$sum", 1)}
});
var sort = new BsonDocument(
"$sort",
new BsonDocument("_id", 1)
);
var args = new AggregateArgs
{
Pipeline = new[] { grouping, sort },
OutputMode = AggregateOutputMode.Cursor,
};
return items.Aggregate(args);
}
What is the best way to do something like this:
var existingEntities = new []
{
new Product {Name = "Name1", Count = 10},
new Product {Name = "Name2", Count = 20}
};
using (var context = new ProductContext())
{
// attach several entities
context.SaveChanges();
}
Should I iterate every entity and set it to State = EntityState.Modified?
Yes, iterating and setting
context.Entry(existingproduct).State = EntityState.Modified;
is the way to go.
Source: https://msdn.microsoft.com/en-us/data/jj592676.aspx
I am working on an application (EF6 Code First approach) that is interacting with a entity/table FloorPlan and has 10 records. I want to delete first 6 records as those are obsolete with new business requirements. Here's how the table currently looks:
To delete this in the Code First approach, I tried following code in disconnected state:
using (var newdbContext = new HomItUpContext())
{
var floorPlansOld = new List<FloorPlan>
{
new FloorPlan { Name = "Unitech Uniworld Gardens 2", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/unitech_uniworld_gardens_2/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Vatika Seven Lamps", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/vatika_seven_lamps/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Bestech Park View Spa", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/bestech_park_view_spa/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Imperia Esfera", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/imperia_esfera/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Raheja Vedas", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/raheja_vedas/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() },
new FloorPlan { Name = "Tulip Violet Grandeur", MainImageUrl = "//cdn.homitup.com/resources/featured-ideas/floor-plans/tulip_violet_grandeur/profile.jpg", IsActive = true, FloorPlanIdeas = new List<FloorPlanIdea>() }
};
floorPlansOld.ForEach(a => newdbContext.FloorPlan.Remove(a));
floorPlansOld.ForEach(a => newdbContext.Entry(a).State = System.Data.Entity.EntityState.Deleted);
newdbContext.SaveChanges();
};
When I run update-database command via package manager console, I get following error:
The object cannot be deleted because it was not found in the ObjectStateManager.
I have also tried without changing the state of the entities but to no avail. I only want to do it in disconnected mode. Can you guys throws some pointers around this problem?
If you want to delete those records the only you need to do is create your entity instances with their existing Ids.
using (var newdbContext = new HomItUpContext())
{
var floorPlansOld = new List<FloorPlan>
{ //Put here the record's Ids you want to delete
new FloorPlan { Id=1 },
new FloorPlan { Id=2 },
new FloorPlan { Id=3 },
new FloorPlan { Id=4 },
new FloorPlan { Id=5 },
new FloorPlan { Id=6 }
};
newdbContext.RemoveRange(floorPlansOld);// You can use RemoveRange method instead a foreach to call Remove method.
newdbContext.SaveChanges();
};
Update
Well, in that case I suggest you make a query first seeking all the entities you want to delete by their names, and after that you can delete them using the RemoveRange method:
var names=new List<string>(){ "Unitech Uniworld Gardens 2", "Vatika Seven Lamps",...};
var entitiesToDelete=newdbContext.FloorPlan.Where(fp=>names.Contains(fp.Name));
newdbContext.RemoveRange(entitiesToDelete);
newdbContext.SaveChanges();
You are removing object from newdbContext.FloorPlan, buy you take them from floorPlansOld.
It looks completely wrong to me.
Try this
var a = newdbContext.FloorPlan.First();
newdbContext.FloorPlan.Remove(a);