I'm trying to insert data on SalesOrderDetail entity, everything works fine, except for the Amount field which remains null. I don't get any error message.
Here is an example of my code :
private void beginCreateSalesOrderDetail()
{
SalesOrderDetail orderDetail = new SalesOrderDetail();
orderDetail.SalesOrderId = new EntityReference()
{
Id = id,
LogicalName = "salesorder"
};
orderDetail.Quantity = element.QuantityOnHand;
orderDetail.ProductId = new EntityReference()
{
Id = element.ProductId,
LogicalName = "product"
};
orderDetail.UoMId = new EntityReference()
{
Id = new Guid("8DDD2AFB-73CF-E111-8140-00155D55B216"),
LogicalName = "uom"
};
orderDetail.TransactionCurrencyId = new EntityReference()
{
Id = new Guid("77D695B5-ACB4-E111-97BC-00155D55B216"),
LogicalName = "transactioncurrency"
};
Money Taxe = new Money();
Money Amount = new Money();
Taxe.Value = Convert.ToDecimal(element.totalCharges);
Amount.Value = Convert.ToDecimal(InvoiceTotal);
orderDetail.Tax = Taxe;
orderDetail.BaseAmount = Amount;
orderDetail.PricePerUnit = element.Price;
orderDetail.Description = element.PDesc;
_context.AddToSalesOrderDetailSet(orderDetail);
_context.BeginSaveChanges(EndCreateSalesOrderDetail, orderDetail);
}
private void EndCreateSalesOrderDetail(IAsyncResult result)
{
try
{
_context.EndSaveChanges(result);
}
catch (Exception ex)
{
}
}
Please note that only the amount which remains null
I get the solution.
Actually, there is a restrictions in crm 2011 to calcul the amounts of products,
We have to create a Price List, and associate each product in the list.
Thank you.
Related
I need to save my list of objects to Firestore database. Below is my code:
How I Create the List of object
private async void LoadPlazaListAndSummary()
{
_plazaList = await _dc.GetPlazas();
foreach(var item in _plazaList)
{
var par = new ParameterManualTags
{
Plaza = item.Code,
Lane = item.Lane,
DateTo = System.DateTime.Now,
DateFrom = System.DateTime.Today
};
var manualCount = await _dc.GetManualAndTransactionCount(par);
var model = new Summary
{
Name = item.Name,
Lane = item.Lane,
Code = item.Code,
DateRun = System.DateTime.Now,
ManualAverage = 100.00,
ManualCount = manualCount[0],
ReadCount = 1,
TotalTransaction = manualCount[1],
Type = item.Type,
Plaza = item,
DateFrom = par.DateFrom,
DateTo = par.DateTo,
RfidAddress = item.ReaderIpAddress,
IsDedicated = item.IsDedicated ? "Dedicated" : "Mixed"
};
model.ManualAverage = Math.Round(ComputeManualPercentage(model), 2);
_summaryList.Add(model);
DgSummary.Items.Add(model);
}
}
This is my sample to save data to Firestore:
public void SetData()
{
if (_isConnected)
{
try
{
var doc = _database.Collection("MyCollection").Document("myDocument");
Dictionary<string, object> data = new Dictionary<string, object>()
{
{"FirstName", "MyFirstName"},
{"LastName", "MyLastName"},
{"PhoneNumber", "PhoneNumber"}
};
var x = doc.SetAsync(data);
Console.WriteLine("Saved");
}
catch (Exception ex)
{
Console.WriteLine($#"An error occured in saving the data: {ex.Message}");
}
}
}
Using my sample code, I can insert one at a time to Firestore but, I do not know how to save a list of objects to Firestore.
I am working to create a sales order with a single product added to the sales order detail and attach that to the sales order.
It is throwing me an error and I am wondering if there is a proper way to performing this action?
Thanks!
public void Create(CrmContextCore _crmContext, Guid productId, UserEntityModel currentuser)
{
var detail = new Entity("salesorderdetail");
{
detail["productid"] = new EntityReference("product", productId);
}
var salesorder = new Entity("salesorder");
{
salesorder["accountid"] = new EntityReference("account", currentuser.AccountId);
salesorder["contactid"] = new EntityReference("contact", currentuser.ContactId );
salesorder["emailaddress"] = currentuser.Email;
salesorder["name"] = "DealerPO123";
salesorder["salesorderdetail"] = detail;
}
_crmContext.ServiceContext.AddObject(salesorder);
_crmContext.ServiceContext.SaveChanges();
}
Sample: Set negative prices in opportunities, quotes, and sales orders.
// Create the sales order.
SalesOrder order = new SalesOrder()
{
Name = "Faux Order",
DateFulfilled = new DateTime(2010, 8, 1),
PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName,
_priceListId),
CustomerId = new EntityReference(Account.EntityLogicalName,
_accountId),
FreightAmount = new Money(20.0M)
};
_orderId = _serviceProxy.Create(order);
order.Id = _orderId;
// Add the product to the order with the price overriden with a
// negative value.
SalesOrderDetail orderDetail = new SalesOrderDetail()
{
ProductId = new EntityReference(Product.EntityLogicalName,
_product1Id),
Quantity = 4,
SalesOrderId = order.ToEntityReference(),
IsPriceOverridden = true,
PricePerUnit = new Money(-40.0M),
UoMId = new EntityReference(UoM.EntityLogicalName,
_defaultUnitId)
};
_orderDetailId = _serviceProxy.Create(orderDetail);
That's when i need to use the Stripe API so when i need it, it will go wrong and make mistakes in the Stripe area as you can see here.
i have : v15.6.1 on Stripe.net
Where it goes wrong is here:
planservice.Create(new StripePlanCreateOptions()
to here:
PlanId = abn.PriceValueUnikId };
all the value I get by json eg userid, pric and pricId there is content in them.
[HttpPost]
public IActionResult Post([FromBody] JObject token)
{
var api = Settings.ConstName.StrinpAPIKeyTest;
StripeConfiguration.SetApiKey(api);
var chargeService = new StripeChargeService();
chargeService.ExpandBalanceTransaction = true;
chargeService.ExpandCustomer = true;
chargeService.ExpandInvoice = true;
//StripeCharge stripeCharge = chargeService.Get(api);
var customerSerive = new StripeCustomerService(api);
var subservice = new StripeSubscriptionService(api);
var planservice = new StripePlanService(api);
var pricId = (int)token.GetValue("pricid");
var pric = (int)token.GetValue("pric");
var userid = (int) Userid();
var abn = _dbContext.PriceValue.FirstOrDefault(i => i.PriceValueId == pricId || i.Price == pric);
//Finder information omkring pakken til den enkelte pakke.
var currentUser = _dbContext.Users.FirstOrDefault(i => i.UserId == userid);
if (currentUser != null)
{
if (abn != null)
{
var orderid = Settings.ValueWordsAndNumbers.OrdreValue();//Orderid
var planType = $"OrderId: {orderid} - Pris: {abn.Price} - Mdr: {abn.Months} UserId: {userid}";
planservice.Create(new StripePlanCreateOptions()//error from here
{
Amount = int.Parse(abn.Price.ToString()) * 100,
Nickname = planType,
Currency = "dkk",
Interval = "month",
IntervalCount = abn.Months,
Id = abn.PriceValueUnikId
});
var newCustomer = new StripeCustomerCreateOptions
{
SourceToken = token["id"].ToString(),
Email = token["email"].ToString(),
PlanId = abn.PriceValueUnikId,
};//error to here
var stripeCustomer = customerSerive.Create(newCustomer);
}
}
var planOptions = new StripePlanCreateOptions() {
Product = new StripePlanProductCreateOptions() {
Name = "planType"
},
Amount = int.Parse(abn.Price.ToString()) * 100,
Nickname = planType,
Currency = "dkk",
Interval = "month",
IntervalCount = abn.Months,
};
var planService = new StripePlanService();
StripePlan plan = planService.Create(planOptions);
API version to 2018-02-06 and add support for Product & Plan API
Now Product is REQUIRED.
you need past ID product or dictionary containing fields used to create a service product.
var planOptions = new StripePlanCreateOptions() {
ProductId ="Product Plan id",
Amount = int.Parse(abn.Price.ToString()) * 100,
Nickname = planType,
Currency = "dkk",
Interval = "month",
IntervalCount = abn.Months,
};
enter image description here
[WebMethod]
public void AddEmployementRequest(EmployementRequest emp)
{
EmployeeSkill employeeSkill = new EmployeeSkill
{
Skill = emp.,
Description = emp.
};
EmployeeLanguage employeeLanguage = new EmployeeLanguage
{
Name = emp.,
ConversationLevel = emp.
};
EmployeeCours employeeCours = new EmployeeCours
{
Date =emp. ,
Course = emp.,
Duration = emp.,
Association = emp.,
Description = emp.
};
EmployementRequest employementRequest = new EmployementRequest
{
Name = emp.Name,
Address = emp.Address,
Surnam = emp.Surnam,
Father = emp.Father,
IDNumber = emp.IDNumber,
IDCardNumber = emp.IDNumber,
IDCity = emp.IDCity,
Birthday = emp.Birthday,
Birthplace = emp.Birthplace,
Nationality = emp.Nationality,
Religion = emp.Religion,
Phone = emp.Phone,
Cell = emp.Cell,
EmergencyAddress = emp.EmergencyAddress,
EmergencyName = emp.EmergencyName,
EmergencyPhone = emp.EmergencyPhone,
ParentedPeople = emp.ParentedPeople,
Gender = emp.Gender,
MarriageStatus = emp.MarriageStatus,
Residency = emp.Residency,
InsuranceCode = emp.InsuranceCode,
InsuranceStatus = emp.InsuranceStatus,
VehicleType = emp.VehicleType,
MilitaryServiceStatus = emp.MilitaryServiceStatus,
EducatedFrom = emp.EducatedFrom,
EducationField = emp.EducationField,
EducationGrade = emp.EducationGrade,
ExtraWorkCapability = emp.ExtraWorkCapability,
LeisureTimeHobbies = emp.LeisureTimeHobbies,
Salary = emp.Salary,
IntroducerName = emp.IntroducerName,
IntroductionMethod = emp.IntroductionMethod,
Illness = emp.Illness,
VehicleStatus = emp.VehicleStatus,
PKEmploymentRequest = Guid.NewGuid(),
};
employementRequest.EmployeeLanguages.Add(employeeLanguage);
employementRequest.EmployeeSkills.Add(employeeSkill);
employementRequest.EmployeeCourses.Add(employeeCours);
using (var db = new UKN_DBNAMEEntities())
{
db.EmployementRequests.Add(employementRequest);
db.SaveChanges();
}
}
I want to insert to all parent and child tables at once ,As you can see I can't access the properties in child tables and also there's no intellisense to show the properties unlike the parent
I think I need a Linq query but I have no idea
have you tried
[WebMethod]
public void AddEmployementRequest(EmployementRequest emp) {
emp.PKEmploymentRequest = Guid.NewGuid();
using (var db = new UKN_DBNAMEEntities()) {
db.EmployementRequests.Add(emp);
db.SaveChanges();
}
}
It may/should do, but...
Consider:
using automapper or the like;
use some query to avoid recreation of Language or Skil
I've got the following code and I wish to set the AssignmentID and the ToDoAssignmentID to the same value. Setting AssignmentID to workOrder.AssignmentID works just fine, but setting ToDoAssignmentID to workOrder.AssignmentID results in ToDoAssignmentID being set to 0. Why is that?
workOrder.ClientID = this.Client.ClientID;
workOrder.AssignmentID = this.WorkOrderID;
workOrder.AssignmentNumber = this.GetNextWorkOrderNumber(this.Client);
workOrder.CustomerID = this._CustomerID;
workOrder.DateCreated = this.Created;
workOrder.DatoAvtaltStart = this.AgreedStart == DateTime.MinValue ? new DateTime().MinSDTValue() : this.AgreedStart;
workOrder.DatoAvtaltSlutt = this.AgreedEnd == DateTime.MinValue ? new DateTime().MinSDTValue() : this.AgreedEnd;
workOrder.DateStopped = this.Ended == DateTime.MinValue ? new DateTime().MinSDTValue() : this.Ended;
workOrder.CreatedByEmployeeID = this._CreatedByEmployeeID;
workOrder.ResponsibleEmployeeID = this._ResponsibleEmployeeID;
workOrder.KoordinatorAnsattId = this._CoordinatorEmployeeID;
workOrder.Description = this.Description;
workOrder.Notes = this.Notes;
workOrder.EstimertTimerFra = this.EstimatedHoursFrom;
workOrder.EstimertTimerTil = this.EstimatedHoursTo;
workOrder.EstimatedBillingDate = this.EstimatedBillingDate;
workOrder.Priority = (byte)this.Priority;
workOrder.OBS = this.OBS;
workOrder.CustomerReference = this.CustomersReference;
workOrder.InterntOrdrenr = this.InternalOrderNumber;
workOrder.EksterntOrdrenr = this.ExternalOrderNumber;
workOrder.AssignmentStatusID = this.WorkOrderStatusID;
foreach (var activity in this.Activities)
{
var ProductID = 0;
try
{
ProductID = activity.Product.ProductID;
}
catch (Exception ex)
{
}
workOrder.Activities.Add(new Activity()
{
ActivityID = activity.ActivityID,
ClientID = activity.Client.ClientID,
AssignmentID = workOrder.AssignmentID,
Description = activity.Description,
Notes = activity.Notes,
IsBillable = activity.Billable,
Priority = (byte)activity.Priority,
ActivityTypeID = activity.ActivityType.TypeID,
PerformedByEmployeeID = activity.PerformedByEmployee.EmployeeID,
ProductID = ProductID,
ToDo = activity.IsPlanned,
ToDoAssignmentID = workOrder.AssignmentID,
ToDoCustomerID = workOrder.CustomerID
});
}
workOrderContext.SubmitChanges();
The key is not to think database style, but ORM style.
So instead of setting keys, you assign entities.
so change
ToDoAssignmentID = workOrder.AssignmentID
to (most probable guess of tablenames, check the definition of your entity) the following assignment of entities
ToDoAssignment = workOrder
This will be handled during SubmitChanges as well.