Example #1
0
        public ActionResult Create(ReceiptNoteModels model)
        {
            try
            {
                model.CreatedBy   = CurrentUser.UserName;
                model.UpdatedBy   = CurrentUser.UserName;
                model.ReceiptBy   = CurrentUser.UserName;
                model.CreatedDate = DateTime.Now;
                model.UpdatedDate = DateTime.Now;
                model.ReceiptDate = DateTime.Now;
                model.ListPurchaseOrder.ForEach(x =>
                {
                    x.ListItem = x.ListItem.Where(z => !z.IsVisible).ToList();
                });
                string msg = "";
                model.ListPurchaseOrder = model.ListPurchaseOrder.Where(x => x.ListItem.Count > 0 && x.Delete != (int)Commons.EStatus.Deleted).ToList();
                //===================
                if (!model.IsPurchaseOrder)
                {
                    model.ListItem = model.ListItem.Where(x => x.Delete != (int)Commons.EStatus.Deleted).ToList();
                    foreach (var itemIngredient in model.ListItem)
                    {
                        int    type      = 0;
                        double BaseUsage = _IngredientFactory.GetUsageUOMForIngredient(itemIngredient.IngredientId, itemIngredient.BaseUOMId, ref type);
                        itemIngredient.BaseReceivingQty = type != 0 ? (BaseUsage * itemIngredient.Qty) : (1 * itemIngredient.Qty);
                    }
                }

                List <string> lstStoreId = lstStore.Select(z => z.Value).ToList();
                bool          result     = _factory.Insert(model, lstStoreId, ref msg);
                if (result)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //model.GetListSupplierFromCompnay(listCompanyId);
                    var ListSupplierInfo = GetListSuppliers(model.StoreId);
                    var ListSupplier     = new SelectList(ListSupplierInfo, "Id", "Name");
                    model.ListSupplier = ListSupplier.ToList();

                    ModelState.AddModelError("StoreId", msg);
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("ReceiptNote_Create: ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }