Ejemplo n.º 1
0
        public JsonResult CreateDetailsJson(List <CuttingSheetDetail> Details)
        {
            string errors11 = "";
            int    test     = 0;

            CuttingSheetDetail Detail = new CuttingSheetDetail();

            foreach (CuttingSheetDetail d in Details)
            {
                try
                {
                    Detail = new CuttingSheetDetail();
                    Detail.CuttingSheetId = int.Parse(d.CuttingSheetId.ToString());
                    Detail.MaterialId     = int.Parse(d.MaterialId.ToString());
                    Detail.qty            = float.Parse(d.qty.ToString());


                    //get material
                    Material material = materialRepository.GetById(Detail.MaterialId);
                    //check availability of item in warehouse
                    float AvailableQty = materialRepository.AvailableQty(material);
                    if (AvailableQty > Detail.qty)
                    {
                        Detail.status = statusList.InStock;
                    }
                    else
                    {
                        Detail.status = statusList.Purchase;
                    }
                    Detail.IssueQty = 0;
                    db.CuttingSheetDetails.Add(Detail);
                    db.SaveChanges();

                    //reserve qty in warehouse
                    materialRepository.ReserveQty(material, Detail.qty);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DeleteConfirmed(Detail.CuttingSheetId);
                    test     = 1;
                    errors11 = errors11 + ex.Message;
                    if (ex.InnerException != null)
                    {
                        if (ex.InnerException.InnerException != null)
                        {
                            errors11 = errors11 + ex.InnerException.InnerException.Message;
                        }
                    }
                    return(Json(errors11));
                }
            }
            if (test == 1)
            {
                return(Json(errors11));
            }
            return(Json("Cutting Sheet Saved Successfully"));
        }