Example #1
0
        public JsonResult SaveSt_ItemCardH(St_ItemCardHVM ObjToSave)
        {
            MsgUnit Msg = new MsgUnit();

            try
            {
                var userId          = User.Identity.GetUserId();
                var UserInfo        = _unitOfWork.User.GetMyInfo(userId);
                var saveSt_ItemCard = new St_ItemCardH();
                saveSt_ItemCard.InsDateTime = DateTime.Now;
                saveSt_ItemCard.OpeningDate = DateTime.Now;
                saveSt_ItemCard.InsUserID   = userId;
                saveSt_ItemCard.CompanyID   = UserInfo.fCompanyId;
                saveSt_ItemCard.ArabicName  = ObjToSave.ArabicName;
                if (String.IsNullOrEmpty(ObjToSave.EnglishName))
                {
                    saveSt_ItemCard.EnglishName = ObjToSave.ArabicName;
                }
                else
                {
                    saveSt_ItemCard.EnglishName = ObjToSave.EnglishName;
                }
                saveSt_ItemCard.GroupCode                             = ObjToSave.GroupCode;
                saveSt_ItemCard.NumberOfPieces                        = ObjToSave.NumberOfPieces;
                saveSt_ItemCard.CBM                                   = ObjToSave.CBM;
                saveSt_ItemCard.ReOrderLimit                          = ObjToSave.ReOrderLimit;
                saveSt_ItemCard.OrderQuantity                         = ObjToSave.OrderQuantity;
                saveSt_ItemCard.ItemUnitNo                            = ObjToSave.ItemUnitNo;
                saveSt_ItemCard.SupplierAccountNumber                 = ObjToSave.SupplierAccountNumber;
                saveSt_ItemCard.StyleNo                               = ObjToSave.StyleNo;
                saveSt_ItemCard.ItemLevelNo                           = ObjToSave.ItemLevelNo;
                saveSt_ItemCard.StopItem                              = ObjToSave.StopItem;
                saveSt_ItemCard.ShowOnline                            = ObjToSave.ShowOnline;
                saveSt_ItemCard.QuantityOnline                        = ObjToSave.QuantityOnline;
                saveSt_ItemCard.SaleOfOfferedArticleIsPermitted       = ObjToSave.SaleOfOfferedArticleIsPermitted;
                saveSt_ItemCard.ItemTypeNo                            = ObjToSave.ItemTypeNo;
                saveSt_ItemCard.FactoryNo                             = ObjToSave.FactoryNo;
                saveSt_ItemCard.NumberOfWorkingDays                   = ObjToSave.NumberOfWorkingDays;
                saveSt_ItemCard.NumberOfStages                        = ObjToSave.NumberOfStages;
                saveSt_ItemCard.WageRate                              = ObjToSave.WageRate;
                saveSt_ItemCard.ApprovingTheWarehouseQuantityLessThan = ObjToSave.ApprovingTheWarehouseQuantityLessThan;
                saveSt_ItemCard.QuantityManufacturing                 = ObjToSave.QuantityManufacturing;
                saveSt_ItemCard.FabricChangeIsAllowed                 = ObjToSave.FabricChangeIsAllowed;
                saveSt_ItemCard.AllowWoodToChangeColor                = ObjToSave.AllowWoodToChangeColor;
                saveSt_ItemCard.FactoryNotes                          = ObjToSave.FactoryNotes;
                saveSt_ItemCard.SalePrice                             = ObjToSave.SalePrice;
                saveSt_ItemCard.TaxRate                               = ObjToSave.TaxRate;
                saveSt_ItemCard.TaxTypeNo                             = ObjToSave.TaxTypeNo;
                saveSt_ItemCard.LocalCost                             = ObjToSave.LocalCost;
                saveSt_ItemCard.ForeignCost                           = ObjToSave.ForeignCost;
                saveSt_ItemCard.TotalCost                             = ObjToSave.TotalCost;
                saveSt_ItemCard.TotalQuantity                         = ObjToSave.TotalQuantity;
                saveSt_ItemCard.NetTotal                              = ObjToSave.NetTotal;
                saveSt_ItemCard.TheTargetMonthlyAmount                = ObjToSave.TheTargetMonthlyAmount;
                saveSt_ItemCard.ItemSerial                            = _unitOfWork.St_ItemCardH.GetMaxSerial(UserInfo.fCompanyId, saveSt_ItemCard.GroupCode);
                saveSt_ItemCard.ItemLogo                              = ObjToSave.ItemLogo;
                int    SerialLength = 5 - saveSt_ItemCard.ItemSerial.ToString().Length;
                string SerialNumber = "";
                for (int i = 0; i <= SerialLength; i++)
                {
                    if (i < SerialLength)
                    {
                        SerialNumber = SerialNumber + "0";
                    }
                    else if (i == SerialLength)
                    {
                        SerialNumber = saveSt_ItemCard.GroupCode + SerialNumber + saveSt_ItemCard.ItemSerial.ToString();
                    }
                }
                saveSt_ItemCard.ItemCode = SerialNumber;
                if (ObjToSave.St_RelatedItemH != null)
                {
                    foreach (var SaveSt_RelatedItem in ObjToSave.St_RelatedItemH)
                    {
                        SaveSt_RelatedItem.CompanyID       = UserInfo.fCompanyId;
                        SaveSt_RelatedItem.ItemCode        = saveSt_ItemCard.ItemCode;
                        SaveSt_RelatedItem.RelatedItemCode = SaveSt_RelatedItem.RelatedItemCode;
                        SaveSt_RelatedItem.RowNumber       = SaveSt_RelatedItem.RowNumber;
                        _unitOfWork.St_ItemCardH.AddRelatedItem(SaveSt_RelatedItem);
                    }
                }
                if (ObjToSave.St_SimilarItemH != null)
                {
                    foreach (var SaveSt_SimilarItem in ObjToSave.St_SimilarItemH)
                    {
                        SaveSt_SimilarItem.CompanyID       = UserInfo.fCompanyId;
                        SaveSt_SimilarItem.ItemCode        = saveSt_ItemCard.ItemCode;
                        SaveSt_SimilarItem.SimilarItemCode = SaveSt_SimilarItem.SimilarItemCode;
                        SaveSt_SimilarItem.RowNumber       = SaveSt_SimilarItem.RowNumber;
                        _unitOfWork.St_ItemCardH.AddSimilarItem(SaveSt_SimilarItem);
                    }
                }

                if (saveSt_ItemCard.ItemTypeNo == 3)
                {
                    foreach (var SaveSt_ManufacturingStage in ObjToSave.St_ManufacturingStageH)
                    {
                        SaveSt_ManufacturingStage.CompanyID    = UserInfo.fCompanyId;
                        SaveSt_ManufacturingStage.ItemCode     = saveSt_ItemCard.ItemCode;
                        SaveSt_ManufacturingStage.FactoryNo    = SaveSt_ManufacturingStage.FactoryNo;
                        SaveSt_ManufacturingStage.RowNumber    = SaveSt_ManufacturingStage.RowNumber;
                        SaveSt_ManufacturingStage.NumberOfDays = SaveSt_ManufacturingStage.NumberOfDays;
                        _unitOfWork.St_ItemCardH.AddManufacturingStage(SaveSt_ManufacturingStage);
                    }
                    if (ObjToSave.St_RawMaterialH != null)
                    {
                        foreach (var SaveSt_RawMaterial in ObjToSave.St_RawMaterialH)
                        {
                            SaveSt_RawMaterial.CompanyID       = UserInfo.fCompanyId;
                            SaveSt_RawMaterial.ItemCode        = saveSt_ItemCard.ItemCode;
                            SaveSt_RawMaterial.RawMaterialCode = SaveSt_RawMaterial.RawMaterialCode;
                            SaveSt_RawMaterial.RowNumber       = SaveSt_RawMaterial.RowNumber;
                            SaveSt_RawMaterial.Quantity        = SaveSt_RawMaterial.Quantity;
                            SaveSt_RawMaterial.Cost            = SaveSt_RawMaterial.Cost;
                            SaveSt_RawMaterial.Total           = SaveSt_RawMaterial.Total;
                            _unitOfWork.St_ItemCardH.AddRawMaterial(SaveSt_RawMaterial);
                        }
                    }
                }
                int iRow = 0;
                if (saveSt_ItemCard.ItemTypeNo == 1)
                {
                    if (ObjToSave.St_SubColorsItemH != null)
                    {
                        foreach (var SaveSubColorsItem in ObjToSave.St_SubColorsItemH)
                        {
                            iRow = iRow + 1;
                            SaveSubColorsItem.CompanyID        = UserInfo.fCompanyId;
                            SaveSubColorsItem.ItemCode         = saveSt_ItemCard.ItemCode;
                            SaveSubColorsItem.SubItemColorCode = SaveSubColorsItem.SubItemColorCode;
                            SaveSubColorsItem.RowNumber        = iRow;
                            _unitOfWork.St_ItemCardH.AddSubColorsItem(SaveSubColorsItem);
                        }
                    }
                }
                iRow = 0;
                if (ObjToSave.St_ItemWarehouseH != null)
                {
                    foreach (var SaveItemWarehouse in ObjToSave.St_ItemWarehouseH)
                    {
                        iRow = iRow + 1;
                        SaveItemWarehouse.CompanyID = UserInfo.fCompanyId;
                        SaveItemWarehouse.ItemCode  = saveSt_ItemCard.ItemCode;
                        SaveItemWarehouse.StockCode = SaveItemWarehouse.StockCode;
                        SaveItemWarehouse.RowNumber = iRow;
                        _unitOfWork.St_ItemCardH.AddItemWarehous(SaveItemWarehouse);
                    }
                }

                if (!ModelState.IsValid)
                {
                    string Err    = " ";
                    var    errors = ModelState.Values.SelectMany(v => v.Errors);
                    foreach (ModelError error in errors)
                    {
                        Err = Err + error.ErrorMessage + " * ";
                    }

                    Msg.Msg  = Resources.Resource.SomthingWentWrong + " : " + Err;
                    Msg.Code = 0;
                    return(Json(Msg, JsonRequestBehavior.AllowGet));
                }
                _unitOfWork.St_ItemCardH.AddItemCard(saveSt_ItemCard);
                _unitOfWork.Complete();
                Msg.Code   = 1;
                Msg.Msg    = Resources.Resource.AddedSuccessfully;
                Msg.LastID = saveSt_ItemCard.ItemCode;
                return(Json(Msg, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Msg.Msg  = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString();
                Msg.Code = 0;
                return(Json(Msg, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
 public void AddItemCard(St_ItemCardH ObjSave)
 {
     _context.St_ItemCradHs.Add(ObjSave);
 }