public async Task <IActionResult> PutUoM(int id, UoM uoM) { if (id != uoM.UoMId) { return(BadRequest()); } _context.Entry(uoM).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UoMExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static List <UoM> GetUoMList() { List <UoM> uoms = new List <UoM>(); OleDbConnection connectionString = new OleDbConnection(DBUtil.GetConnectionString()); string query = "SELECT ID,UoM_Name FROM Uom"; OleDbDataAdapter DataAdapter = new OleDbDataAdapter(query, connectionString); DataSet ds = new DataSet(); try { DataAdapter.Fill(ds, "Uom"); } catch (Exception ex) { throw new Exception("Unable to get UoM" + ex.Message); } DataTable dataTable = ds.Tables[0]; foreach (DataRow dataRow in dataTable.Rows) { UoM objUoM = new UoM(); objUoM.Id = int.Parse(dataRow["ID"].ToString()); objUoM.Name = dataRow["UoM_Name"].ToString(); uoms.Add(objUoM); } return(uoms); }
public dynamic GetInfo(int Id) { UoM model = new UoM(); try { model = _UoMService.GetObjectById(Id); } catch (Exception ex) { LOG.Error("GetInfo", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Id, model.Name, model.Errors }, JsonRequestBehavior.AllowGet)); }
public dynamic Delete(UoM model) { try { if (!AuthenticationModel.IsAllowed("Delete", Core.Constants.Constant.MenuName.UoM, Core.Constants.Constant.MenuGroupName.Master)) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Delete Record"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } var data = _UoMService.GetObjectById(model.Id); model = _UoMService.SoftDeleteObject(data, _itemService); } catch (Exception ex) { LOG.Error("Delete Failed", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Errors })); }
public dynamic Insert(UoM model) { try { if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.UoM, Core.Constants.Constant.MenuGroupName.Master)) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Add record"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } model = _UoMService.CreateObject(model); } catch (Exception ex) { LOG.Error("Insert Failed", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Errors })); }
public async Task <ActionResult <UoM> > PostUoM(UoM uoM) { _context.UoMs.Add(uoM); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUoM", new { id = uoM.UoMId }, uoM)); }
private EntityReference GetDefaultUomReference() { UoM defaultUom = (from uom in XrmContext.UoMSet where uom.Name == defaultUomName select uom).FirstOrDefault(); return(new EntityReference(UoM.EntityLogicalName, defaultUom.UoMId ?? Guid.Empty)); }
public UoM CreateObject(string Name) { UoM unitOfMeasurement = new UoM { Name = Name, }; return(this.CreateObject(unitOfMeasurement)); }
public UoM VHasItem(UoM uom, IItemService _itemService) { IList <Item> list = _itemService.GetObjectsByUoMId(uom.Id); if (list.Any()) { uom.Errors.Add("Generic", "Item tidak boleh ada yang terasosiakan dengan uom"); } return(uom); }
public Item VHasUoM(Item item, IUoMService _uomService) { UoM uom = _uomService.GetObjectById(item.UoMId); if (uom == null) { item.Errors.Add("UoMId", "Tidak terasosiasi dengan Unit of Measurement"); } return(item); }
public CoreBuilder VHasUoM(CoreBuilder coreBuilder, IUoMService _uomService) { UoM uom = _uomService.GetObjectById(coreBuilder.UoMId); if (uom == null) { coreBuilder.Errors.Add("UoMId", "Tidak terasosiasi dengan unit of measurement"); } return(coreBuilder); }
public Barring VHasUoM(Barring barring, IUoMService _uomService) { UoM uom = _uomService.GetObjectById(barring.UoMId); if (uom == null) { barring.Errors.Add("UoMId", "Tidak terasosiasi dengan Unit of Measurement"); } return(barring); }
/// <summary> /// Changes the Edit Result Type fields to the specified ResultType /// </summary> /// <param name="resultType"></param> public void EditResult(ResultType resultType) { Name.Type(resultType.Name); UoM.Type(resultType.UoM); SetCheckBox(IsDefault, resultType.IsDefault); ReportingPeriod.SelectListOptionByText(resultType.ReportingPeriod.ToString()); System.Threading.Thread.Sleep(1000); //give it a couple seconds to catch up SaveButton.Click(); System.Threading.Thread.Sleep(1000); //give it a couple seconds to save }
private void btn_Save_Click(object sender, EventArgs e) { String itemName = txtItemName.Text; String itemPrice = txtItemPrice.Text; String itemBarcode = txtBarcode.Text; String itemSalePrice = txtExpectedSalePrice.Text; String uom = cmbUoM.SelectedValue.ToString(); String vendorId = cmbVendor.SelectedValue.ToString(); try { if (String.IsNullOrEmpty(itemName) || String.IsNullOrEmpty(itemPrice) || String.IsNullOrEmpty(itemSalePrice) || String.IsNullOrEmpty(uom) || vendorId == "0") { MessageBox.Show(this, "Fill in item name, price, sale price,Unit of Measurement and Vendor", "Error:Add Item Type", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { float price = NumberUtils.SafeParse(itemPrice); // float.Parse(itemPrice); float saleprice = NumberUtils.SafeParse(itemSalePrice); //float.Parse(itemSalePrice); ItemType item = new ItemType(); item.ItemName = itemName; item.Price = price; item.SalePrice = saleprice; item.Barcode = itemBarcode; UoM objUoM = new UoM(); objUoM.Id = int.Parse(uom); item.Uom = objUoM; Vendor objVendor = new Vendor(); objVendor.Id = int.Parse(vendorId); item.Vendor = objVendor; bool isInserted = ShopDAL.InsertNewItemType(item); if (isInserted) { this.Close(); MessageBox.Show(this, "Itemtype inserted successfully.", "Add Item Type", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "Itemtype inserted failed.", "Error:Add Item Type", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message.ToString(), "Error:Add Item Type", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public UoM VHasUniqueName(UoM uom, IUoMService _uomService) { if (String.IsNullOrEmpty(uom.Name) || uom.Name.Trim() == "") { uom.Errors.Add("Name", "Tidak boleh kosong"); } if (_uomService.IsNameDuplicated(uom)) { uom.Errors.Add("Name", "Tidak boleh diduplikasi"); } return(uom); }
public static IngredientViewModel FromDataRow(DataRow ingredientRow) { IngredientViewModel ingredientViewModel = new() { Id = Convert.ToInt32(ingredientRow["Id"]), Name = Convert.ToString(ingredientRow["Name"]), Quantity = Convert.ToDecimal(ingredientRow["Quantity"]), UoM = System.Enum.Parse <UoM>(Convert.ToString(ingredientRow["UoM"])) }; return(ingredientViewModel); } }
public string PrintError(UoM obj) { string erroroutput = ""; KeyValuePair <string, string> first = obj.Errors.ElementAt(0); erroroutput += first.Key + "," + first.Value; foreach (KeyValuePair <string, string> pair in obj.Errors.Skip(1)) { erroroutput += Environment.NewLine; erroroutput += pair.Key + "," + pair.Value; } return(erroroutput); }
/// <summary> /// This method creates any entity records that this sample requires. /// Creates the email activity. /// </summary> public static void CreateRequiredRecords(CrmServiceClient service) { // TODO Create entity records Console.WriteLine("Creating required records for the sample"); Console.WriteLine("*****************************************"); // Create a unit group. UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // retrieve the unit id. QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression(), PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; unitQuery.Criteria.AddCondition("uomscheduleid", ConditionOperator.Equal, _unitGroupId); // Retrieve the unit. _unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; Console.WriteLine("Retrieved {0}", _unit.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); Console.WriteLine("*****************************************"); return; }
public dynamic Insert(UoM model) { try { model = _UoMService.CreateObject(model); } catch (Exception ex) { LOG.Error("Insert Failed", ex); model.Errors.Add("Insert Failed", "Error : " + ex); } return(Json(new { model.Errors })); }
public dynamic Delete(UoM model) { try { var data = _UoMService.GetObjectById(model.Id); model = _UoMService.SoftDeleteObject(data, _itemService); } catch (Exception ex) { LOG.Error("Delete Failed", ex); model.Errors.Add("Delete Failed", "Error : " + ex); } return(Json(new { model.Errors })); }
public static bool addUoM(UoM objUom) { OleDbConnection conn = new OleDbConnection(DBUtil.GetConnectionString()); OleDbCommand cmdInsert = new OleDbCommand(); String query = "INSERT INTO Uom ( UoM_Name ) " + "VALUES( @Name )"; int iSqlStatus; cmdInsert.Parameters.Clear(); try { bool isAlreadyExist = DBUtil.IsReferenceExists("Uom", "UoM_Name", objUom.Name); if (isAlreadyExist) { throw new Exception("Unit already exists"); } cmdInsert.CommandText = query; cmdInsert.CommandType = CommandType.Text; cmdInsert.Parameters.AddWithValue("@Name", objUom.Name); cmdInsert.Connection = conn; DBUtil.HandleConnection(conn); iSqlStatus = cmdInsert.ExecuteNonQuery(); if (iSqlStatus == 0) { return(false); } else { return(true); } } catch (Exception ex) { //Now close the connection DBUtil.HandleConnection(conn); throw new Exception(ex.Message.ToString()); } }
public dynamic Update(UoM model) { try { var data = _UoMService.GetObjectById(model.Id); data.Name = model.Name; model = _UoMService.UpdateObject(data); } catch (Exception ex) { LOG.Error("Update Failed", ex); model.Errors.Add("Update Failed", "Error : " + ex); } return(Json(new { model.Errors })); }
private void btnAdd_Click(object sender, EventArgs e) { try { UoM objUom = new UoM(); objUom.Name = txtUnitName.Text.ToString(); if (String.IsNullOrEmpty(objUom.Name)) { throw new Exception(" Unit name must not be empty "); } UoMDAL.addUoM(objUom); MessageBox.Show("Unit added successfully", "Add Unit", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Add Unit", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
public dynamic GetInfo(int Id) { UoM model = new UoM(); try { model = _UoMService.GetObjectById(Id); } catch (Exception ex) { LOG.Error("GetInfo", ex); model.Errors.Add("Error", "Error : " + ex); } return(Json(new { model.Id, model.Name, model.Errors }, JsonRequestBehavior.AllowGet)); }
public override int GetHashCode() { if (Value == null) { if (UoM == null) { return(0); } else { return(UoM.GetHashCode()); } } else if (UoM == null) { return(Value.GetHashCode()); } else { return(((ulong)Value.GetHashCode() | ((ulong)UoM.GetHashCode() << 32)).GetHashCode()); } }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group and price list. /// </summary> public void CreateRequiredRecords() { Console.WriteLine("Creating required records for the sample:"); // Create a unit group. UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // retrieve the unit id. QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression(), PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; unitQuery.Criteria.AddCondition("uomscheduleid", ConditionOperator.Equal, _unitGroupId); // Retrieve the unit. _unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; Console.WriteLine("Retrieved {0}", _unit.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); return; }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group, few products, price list and price list items. /// Create an account record. /// Create few opportunities, opportunity products and a write-in product. /// </summary> public void CreateRequiredRecords() { // Create a unit group. UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // retrieve the unit id. QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression(), PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; unitQuery.Criteria.AddCondition("uomscheduleid", ConditionOperator.Equal, _unitGroupId); // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; Console.WriteLine("Retrieved {0}", unit.Name); // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); // Create a price list items for the products ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); Console.WriteLine("Created price list for {0}", newProduct1.Name); ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); Console.WriteLine("Created price list for {0}", newProduct2.Name); //Publish Product1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); //Publish Product2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published both the products"); // Create an account record for the opportunity's potential customerid Account newAccount = new Account { Name = "Example Account" }; _accountId = _serviceProxy.Create(newAccount); Console.WriteLine("Created {0}", newAccount.Name); // Create a new opportunity Opportunity newOpportunity = new Opportunity { Name = "Example Opportunity", CustomerId = new EntityReference(Account.EntityLogicalName, _accountId), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), FreightAmount = new Money(10.00m) }; _opportunityId = _serviceProxy.Create(newOpportunity); Console.WriteLine("Created {0}", newOpportunity.Name); // Create an opportunity product OpportunityProduct newOpportunityProduct1 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Quantity = 3, Tax = new Money(4.80m) }; _opportunityProduct1Id = _serviceProxy.Create(newOpportunityProduct1); Console.WriteLine("Created opportunity product for {0} and {1}", newOpportunity.Name, newProduct1.Name); // Create a catalog product and override the price per unit OpportunityProduct newOpportunityProduct2 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Quantity = 1, IsPriceOverridden = true, PricePerUnit = new Money(12), Tax = new Money(0.96m) }; _opportunityProduct2Id = _serviceProxy.Create(newOpportunityProduct2); Console.WriteLine("Created opportunity product for {0} and {1}", newOpportunity.Name, newProduct2.Name); // Create a write-in product with a manual discount OpportunityProduct newWriteInProduct = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), // set this attribute to make it a write-in product IsProductOverridden = true, ProductDescription = "Example Write-in Product", PricePerUnit = new Money(20.00m), Quantity = 5, ManualDiscountAmount = new Money(10.50m), Tax = new Money(7.16m) }; _writeInProductId = _serviceProxy.Create(newWriteInProduct); Console.WriteLine("Created {0}", newWriteInProduct.ProductDescription); return; }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { #region Create or Retrieve the necessary system users // Retrieve the ldapPath String ldapPath = String.Empty; // Retrieve the sales team - 1 sales manager and 2 sales representatives. _salesManagerId = SystemUserProvider.RetrieveSalesManager(_serviceProxy, ref ldapPath); _salesRepresentativeIds = SystemUserProvider.RetrieveSalespersons(_serviceProxy, ref ldapPath); #endregion #region Create records to support Opportunity records // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 3, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); // Create a price list item for the first product and apply volume discount ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); // Create a price list item for the second product ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(15) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); //Publish Product1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); //Publish Product2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published both the products"); // Create an account record for the opportunity's potential customerid Account newAccount = new Account { Name = "Margie's Travel", Address1_PostalCode = "99999" }; _accountId = (_serviceProxy.Create(newAccount)); #endregion Create records to support Opportunity records }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group and price list. /// </summary> public void CreateRequiredRecords() { Console.WriteLine("Creating required records for the sample:"); // Create a unit group. UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // retrieve the unit id. QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression(), PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; unitQuery.Criteria.AddCondition("uomscheduleid", ConditionOperator.Equal, _unitGroupId); // Retrieve the unit. unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; Console.WriteLine("Retrieved {0}", unit.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); // Create couple of product records Product newProduct1 = new Product { Name = "Example Product 1", ProductNumber = "P001", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("\nCreated {0}", newProduct1.Name); Product newProduct2 = new Product { Name = "Example Product 2", ProductNumber = "P002", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create price list items for the products ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); Console.WriteLine("Created price list for {0}", newProduct1.Name); ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); Console.WriteLine("Created price list for {0}", newProduct2.Name); Product newBundle = new Product { Name = "Example Bundle", ProductNumber = "B001", ProductStructure = new OptionSetValue(3), QuantityDecimal = 0, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _bundleId = _serviceProxy.Create(newBundle); Console.WriteLine("\nCreated {0}", newBundle.Name); // Create price list item for the bundle ProductPriceLevel newPriceListItem3 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _bundleId), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(200) }; _priceListItem3Id = _serviceProxy.Create(newPriceListItem3); Console.WriteLine("Created price list for {0}", newBundle.Name); return; }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // Create a unit group. UoMSchedule unitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _service.Create(unitGroup); // Retrieve the unit. QueryExpression unitQuery = new QueryExpression() { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = { Conditions = { new ConditionExpression("uomscheduleid", ConditionOperator.Equal, _unitGroupId) } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; UoM unit = (UoM)_service.RetrieveMultiple(unitQuery).Entities[0]; // Create an account. Account account = new Account { Name = "Litware, Inc.", Address1_StateOrProvince = "Colorado" }; _accountId = (_service.Create(account)); // Create the 2 contacts. Contact contact = new Contact() { FirstName = "Ben", LastName = "Andrews", EMailAddress1 = "*****@*****.**", Address1_City = "Redmond", Address1_StateOrProvince = "WA", Address1_Telephone1 = "(206)555-5555", ParentCustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _contactIdList.Add(_service.Create(contact)); contact = new Contact() { FirstName = "Colin", LastName = "Wilcox", EMailAddress1 = "*****@*****.**", Address1_City = "Bellevue", Address1_StateOrProvince = "WA", Address1_Telephone1 = "(425)555-5555", ParentCustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _contactIdList.Add(_service.Create(contact)); // Create pricing and product objects. PriceLevel priceLevel = new PriceLevel() { Name = "Faux Price List" }; _priceLevelId = _service.Create(priceLevel); Product product = new Product() { ProductNumber = "1", QuantityDecimal = 4, Name = "Faux Product", Price = new Money(20.0M), DefaultUoMId = new EntityReference { Id = unit.Id, LogicalName = UoM.EntityLogicalName }, DefaultUoMScheduleId = new EntityReference { Id = _unitGroupId, LogicalName = UoMSchedule.EntityLogicalName } }; _productId = _service.Create(product); ProductPriceLevel productPrice = new ProductPriceLevel() { PriceLevelId = new EntityReference() { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, ProductId = new EntityReference() { Id = _productId, LogicalName = Product.EntityLogicalName }, UoMId = new EntityReference { Id = unit.Id, LogicalName = UoM.EntityLogicalName }, Amount = new Money(20.0M), }; _productPriceId = _service.Create(productPrice); // Create 3 orders. SalesOrder order = new SalesOrder() { Name = "Faux Order", DateFulfilled = new DateTime(2010, 8, 1), PriceLevelId = new EntityReference { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName }, FreightAmount = new Money(20.0M) }; _orderIdList.Add(_service.Create(order)); order = new SalesOrder() { Name = "Old Faux Order", DateFulfilled = new DateTime(2010, 4, 1), PriceLevelId = new EntityReference { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName }, FreightAmount = new Money(20.0M) }; _orderIdList.Add(_service.Create(order)); order = new SalesOrder() { Name = "Oldest Faux Order", DateFulfilled = new DateTime(2008, 8, 1), PriceLevelId = new EntityReference { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName }, FreightAmount = new Money(20.0M) }; _orderIdList.Add(_service.Create(order)); // Create 2 opportunities. Opportunity opportunity = new Opportunity() { Name = "Litware, Inc. Opportunity 1", EstimatedCloseDate = new DateTime(2011, 1, 1), CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _opportunityIdList.Add(_service.Create(opportunity)); opportunity = new Opportunity() { Name = "Litware, Inc. Opportunity 2", EstimatedCloseDate = new DateTime(2020, 1, 1), CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _opportunityIdList.Add(_service.Create(opportunity)); }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { #region create kb articles Console.WriteLine(" Creating KB Articles"); _subjectId = ( from subject in _context.SubjectSet where subject.Title == "Default Subject" select subject.Id ).First(); var kbArticleTemplateId = ( from articleTemplate in _context.KbArticleTemplateSet where articleTemplate.Title == "Standard KB Article" select articleTemplate.Id ).FirstOrDefault(); if (kbArticleTemplateId != Guid.Empty) { // create a KB article _articles[0] = new KbArticle() { // set the article properties Title = "Searching the knowledge base", ArticleXml = @" <articledata> <section id='0'> <content><![CDATA[This is a sample article about searching the knowledge base.]]></content> </section> <section id='1'> <content><![CDATA[Knowledge bases contain information useful for various people.]]></content> </section> </articledata>", // use the built-in "Standard KB Article" template KbArticleTemplateId = new EntityReference(KbArticleTemplate.EntityLogicalName, kbArticleTemplateId), // use the default subject SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), KeyWords = "Searching Knowledge base" }; _context.AddObject(_articles[0]); _articles[1] = new KbArticle() { Title = "What's in a knowledge base", ArticleXml = @" <articledata> <section id='0'> <content><![CDATA[This is a sample article about what would be in a knowledge base.]]></content> </section> <section id='1'> <content><![CDATA[This section contains more information.]]></content> </section> </articledata>", KbArticleTemplateId = new EntityReference(KbArticleTemplate.EntityLogicalName, kbArticleTemplateId), SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), KeyWords = "Knowledge base" }; _context.AddObject(_articles[1]); _articles[2] = new KbArticle() { Title = "Searching the knowledge base from code", ArticleXml = @" <articledata> <section id='0'> <content><![CDATA[This article covers searching the knowledge base from code.]]></content> </section> <section id='1'> <content><![CDATA[This section contains more information.]]></content> </section> </articledata>", KbArticleTemplateId = new EntityReference(KbArticleTemplate.EntityLogicalName, kbArticleTemplateId), SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), KeyWords = "Knowledge base code" }; _context.AddObject(_articles[2]); _context.SaveChanges(); } else { throw new ArgumentException("Standard Article Templates are missing"); } #endregion #region Submit the articles Console.WriteLine(" Submitting the articles"); foreach (var article in _articles) { _context.Execute(new SetStateRequest { EntityMoniker = article.ToEntityReference(), State = new OptionSetValue((int)KbArticleState.Unapproved), Status = new OptionSetValue((int)kbarticle_statuscode.Unapproved) }); } #endregion #region Approve and Publish the article Console.WriteLine(" Publishing articles"); foreach (var article in _articles) { _context.Execute(new SetStateRequest { EntityMoniker = article.ToEntityReference(), State = new OptionSetValue((int)KbArticleState.Published), Status = new OptionSetValue((int)kbarticle_statuscode.Published) }); } #endregion #region Waiting for publishing to finish // Wait 20 seconds to ensure that data will be available // Full-text indexing Console.WriteLine(" Waiting 20 seconds to ensure indexing has completed on the new records."); System.Threading.Thread.Sleep(20000); Console.WriteLine(); #endregion #region Add cases to KbArticles // Create UoM _uomSchedule = new UoMSchedule() { Name = "Sample unit group", BaseUoMName = "Sample base unit" }; _context.AddObject(_uomSchedule); _context.SaveChanges(); _uom = (from uom in _context.UoMSet where uom.Name == _uomSchedule.BaseUoMName select uom).First(); Console.WriteLine(" Creating an account and incidents for the KB articles"); var whoami = (WhoAmIResponse)_context.Execute(new WhoAmIRequest()); _account = new Account() { Name = "Coho Winery", }; _context.AddObject(_account); _context.SaveChanges(); _product = new Product() { Name = "Sample Product", ProductNumber = "0", ProductStructure = new OptionSetValue(1), DefaultUoMScheduleId = _uomSchedule.ToEntityReference(), DefaultUoMId = _uom.ToEntityReference() }; _context.AddObject(_product); _context.SaveChanges(); // Publish Product SetStateRequest publishRequest = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product.Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _context.Execute(publishRequest); _incident = new Incident() { Title = "A sample incident", OwnerId = new EntityReference(SystemUser.EntityLogicalName, whoami.UserId), KbArticleId = _articles[0].ToEntityReference(), CustomerId = _account.ToEntityReference(), SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), ProductId = _product.ToEntityReference() }; _context.AddObject(_incident); _context.SaveChanges(); #endregion }
void before_each() { var db = new OffsetPrintingSuppliesEntities(); using (db) { db.DeleteAllTables(); itemService = new ItemService(new ItemRepository(), new ItemValidator()); contactService = new ContactService(new ContactRepository(), new ContactValidator()); poService = new PurchaseOrderService(new PurchaseOrderRepository(), new PurchaseOrderValidator()); poDetailService = new PurchaseOrderDetailService(new PurchaseOrderDetailRepository(), new PurchaseOrderDetailValidator()); _stockMutationService = new StockMutationService(new StockMutationRepository(), new StockMutationValidator()); _itemTypeService = new ItemTypeService(new ItemTypeRepository(), new ItemTypeValidator()); _uomService = new UoMService(new UoMRepository(), new UoMValidator()); _warehouseItemService = new WarehouseItemService(new WarehouseItemRepository(), new WarehouseItemValidator()); _warehouseService = new WarehouseService(new WarehouseRepository(), new WarehouseValidator()); _barringService = new BarringService(new BarringRepository(), new BarringValidator()); _itemService = new ItemService(new ItemRepository(), new ItemValidator()); _stockAdjustmentService = new StockAdjustmentService(new StockAdjustmentRepository(), new StockAdjustmentValidator()); _stockAdjustmentDetailService = new StockAdjustmentDetailService(new StockAdjustmentDetailRepository(), new StockAdjustmentDetailValidator()); _accountService = new AccountService(new AccountRepository(), new AccountValidator()); _closingService = new ClosingService(new ClosingRepository(), new ClosingValidator()); _generalLedgerJournalService = new GeneralLedgerJournalService(new GeneralLedgerJournalRepository(), new GeneralLedgerJournalValidator()); _priceMutationService = new PriceMutationService(new PriceMutationRepository(), new PriceMutationValidator()); _contactGroupService = new ContactGroupService(new ContactGroupRepository(), new ContactGroupValidator()); if (!_accountService.GetLegacyObjects().Any()) { Asset = _accountService.CreateLegacyObject(new Account() { Name = "Asset", Code = Constant.AccountCode.Asset, LegacyCode = Constant.AccountLegacyCode.Asset, Level = 1, Group = Constant.AccountGroup.Asset, IsLegacy = true }, _accountService); CashBank = _accountService.CreateLegacyObject(new Account() { Name = "CashBank", Code = Constant.AccountCode.CashBank, LegacyCode = Constant.AccountLegacyCode.CashBank, Level = 2, Group = Constant.AccountGroup.Asset, ParentId = Asset.Id, IsLegacy = true }, _accountService); AccountReceivable = _accountService.CreateLegacyObject(new Account() { Name = "Account Receivable", IsLeaf = true, Code = Constant.AccountCode.AccountReceivable, LegacyCode = Constant.AccountLegacyCode.AccountReceivable, Level = 2, Group = Constant.AccountGroup.Asset, ParentId = Asset.Id, IsLegacy = true }, _accountService); GBCHReceivable = _accountService.CreateLegacyObject(new Account() { Name = "GBCH Receivable", IsLeaf = true, Code = Constant.AccountCode.GBCHReceivable, LegacyCode = Constant.AccountLegacyCode.GBCHReceivable, Level = 2, Group = Constant.AccountGroup.Asset, ParentId = Asset.Id, IsLegacy = true }, _accountService); Inventory = _accountService.CreateLegacyObject(new Account() { Name = "Inventory", IsLeaf = true, Code = Constant.AccountCode.Inventory, LegacyCode = Constant.AccountLegacyCode.Inventory, Level = 2, Group = Constant.AccountGroup.Asset, ParentId = Asset.Id, IsLegacy = true }, _accountService); Expense = _accountService.CreateLegacyObject(new Account() { Name = "Expense", Code = Constant.AccountCode.Expense, LegacyCode = Constant.AccountLegacyCode.Expense, Level = 1, Group = Constant.AccountGroup.Expense, IsLegacy = true }, _accountService); CashBankAdjustmentExpense = _accountService.CreateLegacyObject(new Account() { Name = "CashBank Adjustment Expense", IsLeaf = true, Code = Constant.AccountCode.CashBankAdjustmentExpense, LegacyCode = Constant.AccountLegacyCode.CashBankAdjustmentExpense, Level = 2, Group = Constant.AccountGroup.Expense, ParentId = Expense.Id, IsLegacy = true }, _accountService); COGS = _accountService.CreateLegacyObject(new Account() { Name = "Cost Of Goods Sold", IsLeaf = true, Code = Constant.AccountCode.COGS, LegacyCode = Constant.AccountLegacyCode.COGS, Level = 2, Group = Constant.AccountGroup.Expense, ParentId = Expense.Id, IsLegacy = true }, _accountService); Discount = _accountService.CreateLegacyObject(new Account() { Name = "Discount", IsLeaf = true, Code = Constant.AccountCode.Discount, LegacyCode = Constant.AccountLegacyCode.Discount, Level = 2, Group = Constant.AccountGroup.Expense, ParentId = Expense.Id, IsLegacy = true }, _accountService); SalesAllowance = _accountService.CreateLegacyObject(new Account() { Name = "Sales Allowance", IsLeaf = true, Code = Constant.AccountCode.SalesAllowance, LegacyCode = Constant.AccountLegacyCode.SalesAllowance, Level = 2, Group = Constant.AccountGroup.Expense, ParentId = Expense.Id, IsLegacy = true }, _accountService); StockAdjustmentExpense = _accountService.CreateLegacyObject(new Account() { Name = "Stock Adjustment Expense", IsLeaf = true, Code = Constant.AccountCode.StockAdjustmentExpense, LegacyCode = Constant.AccountLegacyCode.StockAdjustmentExpense, Level = 2, Group = Constant.AccountGroup.Expense, ParentId = Expense.Id, IsLegacy = true }, _accountService); Liability = _accountService.CreateLegacyObject(new Account() { Name = "Liability", Code = Constant.AccountCode.Liability, LegacyCode = Constant.AccountLegacyCode.Liability, Level = 1, Group = Constant.AccountGroup.Liability, IsLegacy = true }, _accountService); AccountPayable = _accountService.CreateLegacyObject(new Account() { Name = "Account Payable", IsLeaf = true, Code = Constant.AccountCode.AccountPayable, LegacyCode = Constant.AccountLegacyCode.AccountPayable, Level = 2, Group = Constant.AccountGroup.Liability, ParentId = Liability.Id, IsLegacy = true }, _accountService); GBCHPayable = _accountService.CreateLegacyObject(new Account() { Name = "GBCH Payable", IsLeaf = true, Code = Constant.AccountCode.GBCHPayable, LegacyCode = Constant.AccountLegacyCode.GBCHPayable, Level = 2, Group = Constant.AccountGroup.Liability, ParentId = Liability.Id, IsLegacy = true }, _accountService); GoodsPendingClearance = _accountService.CreateLegacyObject(new Account() { Name = "Goods Pending Clearance", IsLeaf = true, Code = Constant.AccountCode.GoodsPendingClearance, LegacyCode = Constant.AccountLegacyCode.GoodsPendingClearance, Level = 2, Group = Constant.AccountGroup.Liability, ParentId = Liability.Id, IsLegacy = true }, _accountService); Equity = _accountService.CreateLegacyObject(new Account() { Name = "Equity", Code = Constant.AccountCode.Equity, LegacyCode = Constant.AccountLegacyCode.Equity, Level = 1, Group = Constant.AccountGroup.Equity, IsLegacy = true }, _accountService); OwnersEquity = _accountService.CreateLegacyObject(new Account() { Name = "Owners Equity", Code = Constant.AccountCode.OwnersEquity, LegacyCode = Constant.AccountLegacyCode.OwnersEquity, Level = 2, Group = Constant.AccountGroup.Equity, ParentId = Equity.Id, IsLegacy = true }, _accountService); EquityAdjustment = _accountService.CreateLegacyObject(new Account() { Name = "Equity Adjustment", IsLeaf = true, Code = Constant.AccountCode.EquityAdjustment, LegacyCode = Constant.AccountLegacyCode.EquityAdjustment, Level = 3, Group = Constant.AccountGroup.Equity, ParentId = OwnersEquity.Id, IsLegacy = true }, _accountService); Revenue = _accountService.CreateLegacyObject(new Account() { Name = "Revenue", IsLeaf = true, Code = Constant.AccountCode.Revenue, LegacyCode = Constant.AccountLegacyCode.Revenue, Level = 1, Group = Constant.AccountGroup.Revenue, IsLegacy = true }, _accountService); } baseGroup = _contactGroupService.CreateObject(Core.Constants.Constant.GroupType.Base, "Base Group", true); Pcs = new UoM() { Name = "Pcs" }; _uomService.CreateObject(Pcs); contact = new Contact() { Name = "President of Indonesia", Address = "Istana Negara Jl. Veteran No. 16 Jakarta Pusat", ContactNo = "021 3863777", PIC = "Mr. President", PICContactNo = "021 3863777", Email = "*****@*****.**" }; contact = contactService.CreateObject(contact, _contactGroupService); type = _itemTypeService.CreateObject("Item", "Item"); warehouse = new Warehouse() { Name = "Sentral Solusi Data", Description = "Kali Besar Jakarta", Code = "LCL" }; warehouse = _warehouseService.CreateObject(warehouse, _warehouseItemService, itemService); item1 = new Item() { ItemTypeId = _itemTypeService.GetObjectByName("Item").Id, Name = "Batik Tulis", Category = "Item", Sku = "bt123", UoMId = Pcs.Id }; itemService.CreateObject(item1, _uomService, _itemTypeService, _warehouseItemService, _warehouseService, _priceMutationService, _contactGroupService); item2 = new Item() { ItemTypeId = _itemTypeService.GetObjectByName("Item").Id, Name = "Buku Gambar", Category = "Item", Sku = "bg123", UoMId = Pcs.Id }; itemService.CreateObject(item2, _uomService, _itemTypeService, _warehouseItemService, _warehouseService, _priceMutationService, _contactGroupService); StockAdjustment sa = new StockAdjustment() { AdjustmentDate = DateTime.Today, WarehouseId = warehouse.Id, Description = "item adjustment" }; _stockAdjustmentService.CreateObject(sa, _warehouseService); StockAdjustmentDetail sadItem1 = new StockAdjustmentDetail() { ItemId = item1.Id, Quantity = 1000, StockAdjustmentId = sa.Id }; _stockAdjustmentDetailService.CreateObject(sadItem1, _stockAdjustmentService, _itemService, _warehouseItemService); StockAdjustmentDetail sadItem2 = new StockAdjustmentDetail() { ItemId = item2.Id, Quantity = 1000, StockAdjustmentId = sa.Id }; _stockAdjustmentDetailService.CreateObject(sadItem2, _stockAdjustmentService, _itemService, _warehouseItemService); _stockAdjustmentService.ConfirmObject(sa, DateTime.Today, _stockAdjustmentDetailService, _stockMutationService, _itemService, _barringService, _warehouseItemService, _generalLedgerJournalService, _accountService, _closingService); } }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group. /// Retrieve the default unit. /// Create few products. /// Create new discount list and discount. /// Create new price list and few price list items. /// Create an account record. /// Create a new opportunity and few opportunity products. /// </summary> public void CreateRequiredRecords() { // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; Console.WriteLine("Retrieved {0}", unit.Name); // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 3, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a new discount list DiscountType newDiscountType = new DiscountType { Name = "Example Discount List", IsAmountType = false }; _discountTypeId = _serviceProxy.Create(newDiscountType); Console.WriteLine("Created {0}", newDiscountType.Name); // Create a new discount Discount newDiscount = new Discount { DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId), LowQuantity = 5, HighQuantity = 10, Percentage = 3 }; _discountId = _serviceProxy.Create(newDiscount); Console.WriteLine("Created new discount for the {0}.", newDiscountType.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); // Create a price list item for the first product and apply volume discount ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20), DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); Console.WriteLine(@"Created price list item for the {0} and applied volume discount.", newProduct1.Name); // Create a price list item for the second product ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); Console.WriteLine("Created price list item for the {0}.", newProduct1.Name); //Publish Product1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); //Publish Product2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published both the products"); // Create an account record for the opporutnity's potential customerid Account newAccount = new Account { Name = "Example Account" }; _accountId = _serviceProxy.Create(newAccount); Console.WriteLine("Created {0}", newAccount.Name); // Create a new opportunity Opportunity newOpportunity = new Opportunity { Name = "Example Opportunity", CustomerId = new EntityReference(Account.EntityLogicalName, _accountId), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId) }; _opportunityId = _serviceProxy.Create(newOpportunity); Console.WriteLine("Created {0}.", newOpportunity.Name); // Create some opportunity products OpportunityProduct newOpportunityProduct1 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 8 }; _opportunityProduct1Id = _serviceProxy.Create(newOpportunityProduct1); OpportunityProduct newOpportunityProduct2 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 1 }; _opportunityProduct2Id = _serviceProxy.Create( newOpportunityProduct2); Console.WriteLine("Created few opportunity products."); return; }
public Price(decimal value, UoM unitOfMeasure) { _value = value; _unitOfMeasure = unitOfMeasure; }