Example #1
0
        public ActionResult Update(MItem viewModel, FormCollection formCollection)
        {
            MItem mItemToUpdate = _mItemRepository.Get(viewModel.Id);

            mItemToUpdate.ItemCatId = _mItemCatRepository.Get(formCollection["ItemCatId"]);
            mItemToUpdate.BrandId   = _mBrandRepository.Get(formCollection["BrandId"]);
            TransferFormValuesTo(mItemToUpdate, viewModel);
            mItemToUpdate.ModifiedDate = DateTime.Now;
            mItemToUpdate.ModifiedBy   = User.Identity.Name;
            mItemToUpdate.DataStatus   = EnumDataStatus.Updated.ToString();

            //IList<MItemUom> listItemUom = new List<MItemUom>();

            //MItemUom itemUom = new MItemUom(mItemToUpdate);
            //itemUom.ItemUomName = formCollection["ItemUomName"];
            //itemUom.ItemUomPurchasePrice = Convert.ToDecimal(formCollection["ItemUomPurchasePrice"]);
            //itemUom.SetAssignedIdTo(Guid.NewGuid().ToString());

            //listItemUom.Add(itemUom);

            //mItemToUpdate.ItemUoms = listItemUom;


            MItemUom itemUom;

            if (mItemToUpdate.ItemUoms.Count == 0)
            {
                itemUom = new MItemUom(mItemToUpdate);
                itemUom.SetAssignedIdTo(Guid.NewGuid().ToString());
            }
            else
            {
                itemUom = mItemToUpdate.ItemUoms[0];
            }
            itemUom.ItemUomName = formCollection["ItemUomName"];
            UpdateNumericData(itemUom, formCollection);


            mItemToUpdate.ItemUoms.Clear();
            mItemToUpdate.ItemUoms.Add(itemUom);

            _mItemRepository.Update(mItemToUpdate);

            try
            {
                _mItemRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mItemRepository.DbContext.RollbackTransaction();

                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
Example #2
0
 internal static string GetItemUomName(IMItemUomRepository mItemUomRepository, MItem mItem)
 {
     if (mItem != null)
     {
         MItemUom itemUom = mItemUomRepository.GetByItem(mItem);
         if (itemUom != null)
         {
             return(itemUom.ItemUomName);
         }
     }
     return(string.Empty);
 }
Example #3
0
 private void UpdateNumericData(MItemUom itemUom, FormCollection formCollection)
 {
     if (!string.IsNullOrEmpty(formCollection["ItemUomPurchasePrice"]))
     {
         string  wide   = formCollection["ItemUomPurchasePrice"].Replace(",", "");
         decimal?budget = Convert.ToDecimal(wide);
         itemUom.ItemUomPurchasePrice = budget;
     }
     else
     {
         itemUom.ItemUomPurchasePrice = null;
     }
 }
Example #4
0
        public ActionResult Insert(MItem viewModel, FormCollection formCollection)
        {
            MItem mItemToInsert = new MItem();

            TransferFormValuesTo(mItemToInsert, viewModel);
            mItemToInsert.ItemCatId = _mItemCatRepository.Get(formCollection["ItemCatId"]);
            mItemToInsert.BrandId   = _mBrandRepository.Get(formCollection["BrandId"]);

            mItemToInsert.SetAssignedIdTo(viewModel.Id);
            mItemToInsert.CreatedDate = DateTime.Now;
            mItemToInsert.CreatedBy   = User.Identity.Name;
            mItemToInsert.DataStatus  = EnumDataStatus.New.ToString();

            //IList<MItemUom> listItemUom = new List<MItemUom>();

            mItemToInsert.ItemUoms.Clear();

            MItemUom itemUom = new MItemUom(mItemToInsert);

            itemUom.ItemUomName = formCollection["ItemUomName"];
            UpdateNumericData(itemUom, formCollection);
            itemUom.SetAssignedIdTo(Guid.NewGuid().ToString());

            mItemToInsert.ItemUoms.Add(itemUom);

            //mItemToInsert.ItemUoms = listItemUom;

            _mItemRepository.Save(mItemToInsert);

            try
            {
                _mItemRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mItemRepository.DbContext.RollbackTransaction();

                //throw e.GetBaseException();
                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
Example #5
0
 private static void UpdateNumericData(MItemUom itemUom, FormCollection formCollection)
 {
     if (!string.IsNullOrEmpty(formCollection["ItemUomPurchasePrice"]))
     {
         string ItemUomPurchasePrice = formCollection["ItemUomPurchasePrice"].Replace(",", "");
         itemUom.ItemUomPurchasePrice = Convert.ToDecimal(ItemUomPurchasePrice);
     }
     else
     {
         itemUom.ItemUomPurchasePrice = null;
     }
     if (!string.IsNullOrEmpty(formCollection["ItemUomSalePrice"]))
     {
         string ItemUomSalePrice = formCollection["ItemUomSalePrice"].Replace(",", "");
         itemUom.ItemUomSalePrice = Convert.ToDecimal(ItemUomSalePrice);
     }
     else
     {
         itemUom.ItemUomSalePrice = null;
     }
 }