public void Update(St_CompanyTransactionKind ObjUpdate) { var ObjToUpdate = _context.St_CompanyTransactionKinds.FirstOrDefault(m => m.CompanyID == ObjUpdate.CompanyID && m.St_CompanyTransactionKindID == ObjUpdate.St_CompanyTransactionKindID); if (ObjToUpdate != null) { ObjToUpdate.AutoSerial = ObjUpdate.AutoSerial; ObjToUpdate.SymbolSerial = ObjUpdate.SymbolSerial; ObjToUpdate.Symbol = ObjUpdate.Symbol; ObjToUpdate.Serial = ObjUpdate.Serial; ObjToUpdate.InsDateTime = ObjUpdate.InsDateTime; ObjToUpdate.InsUserID = ObjUpdate.InsUserID; } }
public JsonResult Save(St_WarehouseVM ObjSave) { MsgUnit Msg = new MsgUnit(); try { var userId = User.Identity.GetUserId(); var UserInfo = _unitOfWork.User.GetMyInfo(userId); var ObjSaveWarehouse = new St_Warehouse(); ObjSaveWarehouse.InsDateTime = DateTime.Now; ObjSaveWarehouse.InsUserID = userId; ObjSaveWarehouse.CompanyID = UserInfo.fCompanyId; ObjSaveWarehouse.StockCode = ObjSave.StockCode; ObjSaveWarehouse.AccountNumber = ObjSave.AccountNumber; ObjSaveWarehouse.CostCenterNumber = ObjSave.CostCenterNumber; ObjSaveWarehouse.Telephone = ObjSave.Telephone; ObjSaveWarehouse.Address = ObjSave.Address; ObjSaveWarehouse.ArabicName = ObjSave.ArabicName; if (String.IsNullOrEmpty(ObjSave.EnglishName)) { ObjSaveWarehouse.EnglishName = ObjSaveWarehouse.ArabicName; } else { ObjSaveWarehouse.EnglishName = ObjSave.EnglishName; } 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)); } var St_TransactionAllStockTransaction = _unitOfWork.NativeSql.GetSt_TransactionKindAllStockTransaction(UserInfo.fCompanyId); if (St_TransactionAllStockTransaction.Count() == 0) { St_TransactionAllStockTransaction = _unitOfWork.NativeSql.GetSt_TransactionKind(); foreach (var SaveSt_TransactionAllStockTransaction in St_TransactionAllStockTransaction) { var St_CompanyTransationKindObj = new St_CompanyTransactionKind(); St_CompanyTransationKindObj.CompanyID = UserInfo.fCompanyId; St_CompanyTransationKindObj.St_CompanyTransactionKindID = _unitOfWork.St_CompanyTransactionKind.GetMaxSerial(UserInfo.fCompanyId); St_CompanyTransationKindObj.St_TransactionKindID = SaveSt_TransactionAllStockTransaction.St_TransactionKindID; St_CompanyTransationKindObj.StockCode = "*"; St_CompanyTransationKindObj.AutoSerial = true; St_CompanyTransationKindObj.SymbolSerial = false; St_CompanyTransationKindObj.Symbol = ""; St_CompanyTransationKindObj.Serial = 0; St_CompanyTransationKindObj.InsUserID = userId; St_CompanyTransationKindObj.InsDateTime = DateTime.Now; _unitOfWork.St_CompanyTransactionKind.Add(St_CompanyTransationKindObj); _unitOfWork.Complete(); } } var St_TransactionAllWithoutStockTransaction = _unitOfWork.NativeSql.GetSt_TransactionKindWithoutAllStockTransaction(); foreach (var SaveSt_TransactionWithoutAllStockTransaction in St_TransactionAllWithoutStockTransaction) { var St_CompanyTransationKindObj = new St_CompanyTransactionKind(); St_CompanyTransationKindObj.CompanyID = UserInfo.fCompanyId; St_CompanyTransationKindObj.St_CompanyTransactionKindID = _unitOfWork.St_CompanyTransactionKind.GetMaxSerial(UserInfo.fCompanyId); St_CompanyTransationKindObj.St_TransactionKindID = SaveSt_TransactionWithoutAllStockTransaction.St_TransactionKindID; St_CompanyTransationKindObj.StockCode = ObjSaveWarehouse.StockCode; St_CompanyTransationKindObj.AutoSerial = true; St_CompanyTransationKindObj.SymbolSerial = false; St_CompanyTransationKindObj.Symbol = ""; St_CompanyTransationKindObj.Serial = 0; St_CompanyTransationKindObj.InsUserID = userId; St_CompanyTransationKindObj.InsDateTime = DateTime.Now; _unitOfWork.St_CompanyTransactionKind.Add(St_CompanyTransationKindObj); _unitOfWork.Complete(); } _unitOfWork.St_Warehouse.Add(ObjSaveWarehouse); _unitOfWork.Complete(); Msg.Code = 1; Msg.Msg = Resources.Resource.AddedSuccessfully; return(Json(Msg, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString(); Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } }
public void Add(St_CompanyTransactionKind ObjSave) { _context.St_CompanyTransactionKinds.Add(ObjSave); }
public JsonResult UpdateSt_CompanyTransactionKind(St_CompanyTransactionKind ObjUpdate) { MsgUnit Msg = new MsgUnit(); try { var userId = User.Identity.GetUserId(); var UserInfo = _unitOfWork.User.GetMyInfo(userId); ObjUpdate.InsDateTime = DateTime.Now; ObjUpdate.InsUserID = userId; ObjUpdate.CompanyID = UserInfo.fCompanyId; 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)); } if (ObjUpdate.SymbolSerial) { var Obj = new St_CompanyTransactionKindSymbolSerial(); var CheckIfSave = _unitOfWork.St_CompanyTransactionKindSymbolSerial.CheckIfSave(ObjUpdate.CompanyID, ObjUpdate.St_CompanyTransactionKindID); if (CheckIfSave == null) { _unitOfWork.St_CompanyTransactionKindSymbolSerial.Delete(ObjUpdate.CompanyID, ObjUpdate.St_CompanyTransactionKindID); _unitOfWork.Complete(); Obj.CompanyID = ObjUpdate.CompanyID; Obj.StockCode = ObjUpdate.StockCode; Obj.St_CompanyTransactionKindID = ObjUpdate.St_CompanyTransactionKindID; Obj.LastSerial = 0; _unitOfWork.St_CompanyTransactionKindSymbolSerial.Add(Obj); _unitOfWork.Complete(); } } else { var Obj = new St_CompanyTransactionKindSymbolSerial(); var CheckIfSave = _unitOfWork.St_CompanyTransactionKindSymbolSerial.CheckIfSave(ObjUpdate.CompanyID, ObjUpdate.St_CompanyTransactionKindID); if (CheckIfSave != null) { _unitOfWork.St_CompanyTransactionKindSymbolSerial.Delete(ObjUpdate.CompanyID, ObjUpdate.St_CompanyTransactionKindID); _unitOfWork.Complete(); } } _unitOfWork.St_CompanyTransactionKind.Update(ObjUpdate); _unitOfWork.Complete(); Msg.Code = 1; Msg.Msg = Resources.Resource.UpdatedSuccessfully; return(Json(Msg, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString(); Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } }