public IActionResult SyncDoc() { { using (var dbdoc = new web_dbDocument.db_Context()) { using (var db = new web_db.sardweb_Context()) { foreach (var item in db.TblDocuments.Take(100)) { dbdoc.TblDocuments.Add(new web_dbDocument.TblDocument { Date = item.Date, FkP = item.FkP, FkPortage = item.FkPortage, fkuser = item.fkuser, Format = item.Format, Id = item.Id, Image = item.Image, Kind = item.Kind }); db.Remove(item); } db.SaveChanges(); dbdoc.SaveChanges(); } } } return(RedirectToAction("Index")); }
public static bool RemoveFullPortage(Guid id, web_db.sardweb_Context db) { var portage = db.TblPortages.Find(id); var contypeclone = db.TblContractTypes.Single(a => a.Id == portage.FkContracttype); #region rem PortageRows foreach (var item in db.TblPortageRows.Where(a => a.FkPortage == portage.Id)) { db.TblPortageRowInjuries.RemoveRange(db.TblPortageRowInjuries.Where(a => a.FkPortageRow == item.Id)); db.TblPortageRows.Remove(item); } #endregion #region rem images var dbdoc = new web_dbDocument.db_Context(); dbdoc.TblDocuments.RemoveRange(dbdoc.TblDocuments.Where(a => a.FkPortage == portage.Id)); db.TblPortages.Remove(portage); #endregion db.SaveChanges(); dbdoc.SaveChanges(); return(true); }
public IActionResult Create(web_db._Weighing.TblCar model, IFormFile file) { if (!ModelState.IsValid) { ViewBag.error = "ثبت انجام نشد - فیلد ها را درست پر کنید"; return(View(model)); } try { var x = db.TblCars.Find(model.Id); if (x == null) { x = new web_db._Weighing.TblCar { Id = model.Id, PriceTowBascol = 0 }; db.TblCars.Add(x); } x.Title = model.Title; x.IsDel = model.IsDel; x.PriceTowBascol = model.PriceTowBascol; var dbdoc = new web_dbDocument.db_Context(); if (file != null) { var r = dbdoc.TblDocuments.FirstOrDefault(a => a.FkP == x.Id); if (r == null) { r = new web_dbDocument.TblDocument { Date = DateTime.Now, FkP = x.Id, fkuser = User._getuserid(), Id = Guid.NewGuid(), Kind = "Image" }; dbdoc.TblDocuments.Add(r); } r.Image = file.ToByteArray().imgTosmall(); } db.SaveChanges(); dbdoc.SaveChanges(); ViewBag.txt = "ثبت انجام شد"; Models.cl._ListCar = db.TblCars.OrderBy(a => a.Title).ToList(); return(RedirectToAction(nameof(Index))); } catch { ViewBag.error = "ثبت انجام نشد"; } return(View(model)); }
public IActionResult DocUpload(IList <IFormFile> files, Guid idp, string kind = "") { var db = new web_dbDocument.db_Context(); foreach (IFormFile source in files) { string Extension = Path.GetExtension(source.FileName).ToLowerInvariant(); if (Extension.IsEmpty()) { Extension = ".jpg"; } if (kind.IsEmpty() == false) { var v = db.TblDocuments.FirstOrDefault(a => a.Kind == kind && (a.FkP == idp || a.FkPortage == idp)); if (v != null) { db.TblDocuments.Remove(v); } } web_dbDocument.TblDocument x = new web_dbDocument.TblDocument { Id = Guid.NewGuid(), FkP = idp, Kind = kind.IsEmpty() ? "" : kind, Date = DateTime.Now, fkuser = User._getuserid() }; db.TblDocuments.Add(x); x.Date = DateTime.Now; using (var target = new MemoryStream()) { source.CopyTo(target); x.Image = target.ToArray(); } x.Format = Extension; if ((Extension).IsImage()) { x.Image = x.Image.imgTosmall(web_lib.FilesHelper.imageSize.s800); } } db.SaveChanges(); return(Content("OK")); }
public IActionResult DocRemove(Guid id) { try { var db = new web_dbDocument.db_Context(); var x = db.TblDocuments.Find(id); if (x != null && x.Kind.IsEmpty()) { db.TblDocuments.Remove(x); db.SaveChanges(); } } catch { } return(Content("OK")); }
public static bool RemoveFullPortage(Guid id, web_db.sardweb_Context db) { var portage = db.TblPortages.Find(id); var contypeclone = db.TblContractTypes.Single(a => a.Id == portage.FkContracttype); #region rem PortageRows foreach (var item in db.TblPortageRows.Where(a => a.FkPortage == portage.Id)) { db.TblPortageRowInjuries.RemoveRange(db.TblPortageRowInjuries.Where(a => a.FkPortageRow == item.Id)); db.TblPortageRows.Remove(item); } #endregion #region rem images var dbdoc = new web_dbDocument.db_Context(); dbdoc.TblDocuments.RemoveRange(dbdoc.TblDocuments.Where(a => a.FkPortage == portage.Id)); db.TblPortages.Remove(portage); #endregion db.SaveChanges(); dbdoc.SaveChanges(); if (contypeclone.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane) { var x = db.TblPortageRows.Where(a => a.FkPortage == portage.Id); foreach (var item in x.Select(a => a.FkContract).Distinct()) { Models.cl.refTblStoreLogcontractSardKhane(item.Value, db); } } return(true); }
public IActionResult CreateOut(Models.tbls.portage.portage model, bool resendSms, string print) { var x = db.TblPortages.Find(model.Id); model.ContractType = cl._ListContractType(User._getuserSalMaliDef()).Single(a => a.Id == model.FkContractType); ModelState.Remove("FkCarTbl"); if (model.ContractType.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad) { ModelState.Remove("Date1date"); ModelState.Remove("Date1time"); ModelState.Remove("Customer.Mob"); ModelState.Remove("Customer.NationalCode"); ModelState.Remove("Customer.Code"); ModelState.Remove("Customer.Title"); ModelState.Remove("Customer.Id"); ModelState.Remove("Weight1"); ModelState.Remove("Weight2"); if (ModelState.IsValid) { x.CarMashin = model.CarMashin; x.CarRanande = model.CarRanande; x.CarShMashin = model.CarShMashin; x.FkCar = model.FkCar; x.CarMashin = cl._ListCar.Single(a => a.Id == model.FkCar).Title; x.CarTell = model.CarTell; var dbdoc = new web_dbDocument.db_Context(); if (x.Weight2 != model.Weight2) { var z = cl.captureDorbinBaskul(); if (z != null) { dbdoc.TblDocuments.Add(new web_dbDocument.TblDocument { Date = DateTime.Now, FkP = x.Id, Id = Guid.NewGuid(), Image = z, Kind = "OutBaskul", Format = "" }); } } x.Weight2 = model.Weight2; x.WeightNet = (x.Weight2 - x.Weight1).gadrmotlagh(); x.Weight2IsBascul = model.Weight2IsBascul; x.Txt = model.Txt; x.Date2 = model.Date2date.ToDate().AddHours(model.Date2time.Value.Hours).AddMinutes(model.Date2time.Value.Minutes); x.IsDel = false; if (x.Dateadd2.HasValue == false) { x.Dateadd2 = DateTime.Now; x.FkUsAdd2 = User._getuserid(); } else { x.Dateedit2 = DateTime.Now; x.FkUsEdit2 = User._getuserid(); } x.IsPermitOk = null; x.FkUsPermit = null; x.TxtPermit = ""; x.IsEnd = false; { x.SmsOk = resendSms == true ? null : (x.SmsOk == true ? (bool?)true : false); } ViewBag.error = checkportage(x); if (((string)ViewBag.error).IsEmpty()) { using (var trans = new TransactionScope()) { Models.cl._refstoreOne(db, x.Id); x.IsPermitOk = contract.IsPermitOK(x, db); if (x.IsPermitOk == true) { x.IsEnd = true; x.TxtPermit = ""; x.FkUsPermit = null; } else { x.IsEnd = false; } db.SaveChanges(); Models.cl._refstoreTow(db, x.Id); trans.Complete(); } dbdoc.SaveChanges(); if (x.IsPermitOk == false) { return(RedirectToAction("CreateOut", x.Id)); } if (string.IsNullOrEmpty(print)) { return(RedirectToAction("index", new { idtype = x.FkContracttype, kindPortage = x.KindCode })); } return(RedirectToAction("Print", new { id = x.Id })); } } ViewData["type"] = db.TblContractTypes.Find(x.FkContracttype); ViewData["kindPortage"] = x.KindCode; // model.Documents = db.TblDocuments.Where(a => a.FkPortage == model.Id).Select(a => new Models.tbls.portage.PortageDocument(a)).ToList(); model.ListRows = db.TblPortageRows.Where(a => a.FkPortage == model.Id).Select(a => new Models.tbls.portage.PortageRow(a, db, false)).ToList(); } return(View(model)); }
public IActionResult CreateIN(Guid idtype, int kindPortage, Models.tbls.portage.portage model) { ModelState.Remove("Weight2"); ModelState.Remove("Date2date"); ModelState.Remove("Date2time"); ModelState.Remove("Customer.Mob"); ModelState.Remove("Customer.NationalCode"); ModelState.Remove("Customer.Code"); ModelState.Remove("Customer.Title"); ModelState.Remove("Customer.Id"); ModelState.Remove("FkCarTbl"); var typecontract = db.TblContractTypes.Find(idtype); if (typecontract.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad) { ModelState.Remove("Weight1"); var conf = typecontract.ConfigASabad(); if (ModelState.IsValid) { var x = db.TblPortages.Find(model.Id); if (x == null) { model.Code = (db.TblPortages.Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.FkContracttype == idtype && a.KindCode == kindPortage).Max(a => (long?)a.Code) ?? 0) + 1; x = new web_db._Weighing.TblPortage { FkSalmali = User._getuserSalMaliDef(), Code = model.Code, Dateadd1 = DateTime.Now, FkContracttype = idtype, FkUsAdd1 = User._getuserid().Value, Id = model.Id, KindCode = kindPortage, KindTitle = Models.tbls.portage.kindPortage.listkindcontract.Find(a => a.code == kindPortage).txt, }; db.TblPortages.Add(x); } else { x.Dateedit1 = DateTime.Now; x.FkUsEdit1 = User._getuserid().Value; } x.CarMashin = model.CarMashin; x.CarRanande = model.CarRanande; x.CarShMashin = model.CarShMashin; x.CarTell = model.CarTell; x.FkCar = model.FkCar; x.CarMashin = cl._ListCar.Single(a => a.Id == model.FkCar).Title; x.FkCustomer = model.FkCustomer; var dbdoc = new web_dbDocument.db_Context(); if (x.Weight1 != model.Weight1) { var z = cl.captureDorbinBaskul(); if (z != null) { dbdoc.TblDocuments.Add(new web_dbDocument.TblDocument { Date = DateTime.Now, FkP = x.Id, Id = Guid.NewGuid(), Image = z, Kind = "InBaskul", Format = "" }); } } x.Weight1 = model.Weight1; x.Weight1IsBascul = model.Weight1IsBascul; x.Txt = model.Txt; x.Date1 = model.Date1date.ToDate().AddHours(model.Date1time.Hours).AddMinutes(model.Date1time.Minutes); x.IsDel = false; x.IsPermitOk = null; x.FkUsPermit = null; x.TxtPermit = ""; ViewBag.error = checkportage(x); if (((string)ViewBag.error).IsEmpty()) { db.SaveChanges(); dbdoc.SaveChanges(); Models.cl._refstoreTow(db, x.Id); return(RedirectToAction("index", new { idtype = x.FkContracttype })); } } ViewData["type"] = db.TblContractTypes.Find(idtype); ViewData["kindPortage"] = kindPortage; ViewData["listcustumer"] = cus(typecontract, model); return(View(model)); } return(null); }
public IActionResult addDoc(Guid id, Guid idp, IFormFile image = null, bool del = false, string kind = "Yard") { var dbdoc = new web_dbDocument.db_Context(); if (del) { var x = dbdoc.TblDocuments.Find(id); var pp = db.TblPortages.Find(x.FkPortage); if ((pp.FkSalmali != User._getuserSalMaliDef()) || (pp.IsEnd) || (pp.IsDel)) { return(RedirectToAction("index")); } dbdoc.TblDocuments.Remove(x); } else { var pp = db.TblPortages.Find(idp); if ((pp.FkSalmali != User._getuserSalMaliDef()) || (pp.IsEnd) || (pp.IsDel)) { return(RedirectToAction("index")); } web_dbDocument.TblDocument x = null; if (kind == "Sign") { x = dbdoc.TblDocuments.FirstOrDefault(a => a.FkPortage == idp && a.Kind == kind); } if (kind == "SignPermit") { x = dbdoc.TblDocuments.FirstOrDefault(a => a.FkPortage == idp && a.Kind == kind); } if (x == null) { x = new web_dbDocument.TblDocument { Id = Guid.NewGuid(), FkPortage = idp, Kind = kind }; dbdoc.TblDocuments.Add(x); } x.Date = DateTime.Now; using (var target = new MemoryStream()) { image.CopyTo(target); x.Image = target.ToArray(); } x.Image = x.Image.imgTosmall(web_lib.FilesHelper.imageSize.s800); } dbdoc.SaveChanges(); return(RedirectToAction("view", new { id = idp, openkind = 1 })); }
private porret[] ClonePortage(Guid id, int setYear, bool image) { var portage = db.TblPortages.Find(id); var customer = db.TblCustomers.Find(portage.FkCustomer); var Clone = db.TblPortages.SingleOrDefault(a => a.Code == portage.Code && a.KindCode == portage.KindCode && a.FkSalmali == setYear); var contype = db.TblContractTypes.Find(portage.FkContracttype); var contypeclone = db.TblContractTypes.Single(a => a.Code == contype.Code && a.FkSalmali == setYear); var customerClone = db.TblCustomers.SingleOrDefault(a => a.Code == customer.Code && a.FkSalmali == setYear);; if (contypeclone.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane) { #region Clone Portage { if (Clone == null) { Clone = new web_db._Weighing.TblPortage { FkSalmali = setYear, Id = Guid.NewGuid(), }; db.TblPortages.Add(Clone); } Clone.FkContracttype = contypeclone.Id; Clone.FkCustomer = customerClone.Id; Clone.CarMashin = portage.CarMashin; Clone.CarRanande = portage.CarRanande; Clone.CarShMashin = portage.CarShMashin; Clone.CarTell = portage.CarTell; Clone.Code = portage.Code; Clone.Date1 = portage.Date1; Clone.Date2 = portage.Date2; Clone.Dateadd1 = portage.Dateadd1; Clone.Dateadd2 = portage.Dateadd2; Clone.Dateedit1 = portage.Dateedit1; Clone.Dateedit2 = portage.Dateedit2; Clone.FkCar = portage.FkCar; Clone.FkUsAdd1 = portage.FkUsAdd1; Clone.FkUsAdd2 = portage.FkUsAdd2; Clone.FkUsEdit1 = portage.FkUsEdit1; Clone.FkUsEdit2 = portage.FkUsEdit2; Clone.FkUsPermit = portage.FkUsPermit; Clone.IsDel = portage.IsDel; Clone.IsEnd = portage.IsEnd; Clone.IsPermitOk = portage.IsPermitOk; Clone.KindCode = portage.KindCode; Clone.KindTitle = portage.KindTitle; Clone.OtcodeResid = portage.OtcodeResid; Clone.PackingCount = portage.PackingCount; Clone.PackingOfWeight = portage.PackingOfWeight; Clone.SmsOk = portage.SmsOk; // Clone.SaveFaktor = portage.SaveFaktor; Clone.SmsVaziat = portage.SmsVaziat; // Clone.SumMoney = portage.SumMoney; Clone.Txt = portage.Txt; Clone.Weight1 = portage.Weight1; Clone.Weight1IsBascul = portage.Weight1IsBascul; Clone.TxtPermit = portage.TxtPermit; Clone.Weight2 = portage.Weight2; Clone.Weight2IsBascul = portage.Weight2IsBascul; Clone.WeightNet = portage.WeightNet; } #endregion #region Clone PortageRows foreach (var item in db.TblPortageRows.Include(a => a.TblPortageRowInjuries).Where(a => a.FkPortage == Clone.Id)) { db.TblPortageRowInjuries.RemoveRange(item.TblPortageRowInjuries); db.TblPortageRows.Remove(item); } foreach (var item in db.TblPortageRows.Include(a => a.TblPortageRowInjuries).Where(a => a.FkPortage == portage.Id)) { var cont = db.TblContracts.Find(item.FkContract); var contClone = db.TblContracts.Single(a => a.Code == cont.Code && a.FkSalmali == setYear); var v = new web_db._Weighing.TblPortageRow { Id = Guid.NewGuid(), FkContractType = Clone.FkContracttype, FkContract = contClone.Id, FkPortage = Clone.Id, Code = item.Code, CodeLocation = item.CodeLocation, Count = item.Count, Date = item.Date, FkLocation1 = item.FkLocation1, FkLocation2 = item.FkLocation2, FkLocation3 = item.FkLocation3, FkPacking = item.FkPacking, FkProduct = item.FkProduct, FkUser = item.FkUser, IsNimPalet = item.IsNimPalet, Txt = item.Txt, WeightOne = item.WeightOne }; db.TblPortageRows.Add(v); foreach (var iteminj in item.TblPortageRowInjuries) { db.TblPortageRowInjuries.Add(new web_db._Weighing.TblPortageRowInjury { FkInjury = iteminj.FkInjury, FkPortageRow = v.Id }); } } #endregion #region Clone images var dbdoc = new web_dbDocument.db_Context(); dbdoc.TblDocuments.RemoveRange(dbdoc.TblDocuments.Where(a => a.FkPortage == Clone.Id || a.FkP == Clone.Id)); if (image) { foreach (var item in dbdoc.TblDocuments.Where(a => a.FkPortage == portage.Id)) { var c = new web_dbDocument.TblDocument { Id = Guid.NewGuid(), Date = item.Date, Image = item.Image, Kind = item.Kind, FkP = Clone.Id, Format = item.Format }; dbdoc.TblDocuments.Add(c); } } #endregion db.SaveChanges(); dbdoc.SaveChanges(); var x = db.TblPortageRows.Where(a => a.FkPortage == Clone.Id); return(x.Select(a => new porret { id = (Guid)a.FkContract, Product = true }).Distinct().ToArray()); } else if (contypeclone.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad) { #region Clone Portage { if (Clone == null) { Clone = new web_db._Weighing.TblPortage { FkSalmali = setYear, Id = Guid.NewGuid(), }; db.TblPortages.Add(Clone); } Clone.FkContracttype = contypeclone.Id; Clone.FkCustomer = customerClone.Id; Clone.CarMashin = portage.CarMashin; Clone.CarRanande = portage.CarRanande; Clone.CarShMashin = portage.CarShMashin; Clone.CarTell = portage.CarTell; Clone.Code = portage.Code; Clone.Date1 = portage.Date1; Clone.Date2 = portage.Date2; Clone.Dateadd1 = portage.Dateadd1; Clone.Dateadd2 = portage.Dateadd2; Clone.Dateedit1 = portage.Dateedit1; Clone.Dateedit2 = portage.Dateedit2; Clone.FkCar = portage.FkCar; Clone.FkUsAdd1 = portage.FkUsAdd1; Clone.FkUsAdd2 = portage.FkUsAdd2; Clone.FkUsEdit1 = portage.FkUsEdit1; Clone.FkUsEdit2 = portage.FkUsEdit2; Clone.FkUsPermit = portage.FkUsPermit; Clone.IsDel = portage.IsDel; Clone.IsEnd = portage.IsEnd; Clone.IsPermitOk = portage.IsPermitOk; Clone.KindCode = portage.KindCode; Clone.KindTitle = portage.KindTitle; Clone.OtcodeResid = portage.OtcodeResid; Clone.PackingCount = portage.PackingCount; Clone.PackingOfWeight = portage.PackingOfWeight; Clone.SmsOk = portage.SmsOk; // Clone.SaveFaktor = portage.SaveFaktor; Clone.SmsVaziat = portage.SmsVaziat; // Clone.SumMoney = portage.SumMoney; Clone.Txt = portage.Txt; Clone.Weight1 = portage.Weight1; Clone.Weight1IsBascul = portage.Weight1IsBascul; Clone.TxtPermit = portage.TxtPermit; Clone.Weight2 = portage.Weight2; Clone.Weight2IsBascul = portage.Weight2IsBascul; Clone.WeightNet = portage.WeightNet; } #endregion #region Clone PortageRows foreach (var item in db.TblPortageRows.Where(a => a.FkPortage == Clone.Id)) { db.TblPortageRowInjuries.RemoveRange(db.TblPortageRowInjuries.Where(a => a.FkPortageRow == item.Id)); db.TblPortageRows.Remove(item); } foreach (var item in db.TblPortageRows.Where(a => a.FkPortage == portage.Id)) { var cont = db.TblContracts.Find(item.FkContract); var contClone = db.TblContracts.Single(a => a.Code == cont.Code && a.FkSalmali == setYear); var v = new web_db._Weighing.TblPortageRow { Id = Guid.NewGuid(), FkContractType = Clone.FkContracttype, FkContract = contClone.Id, FkPortage = Clone.Id, Code = item.Code, CodeLocation = item.CodeLocation, Count = item.Count, Date = item.Date, FkLocation1 = item.FkLocation1, FkLocation2 = item.FkLocation2, FkLocation3 = item.FkLocation3, FkPacking = item.FkPacking, FkProduct = item.FkProduct, FkUser = item.FkUser, IsNimPalet = item.IsNimPalet, Txt = item.Txt, WeightOne = item.WeightOne }; db.TblPortageRows.Add(v); foreach (var iteminj in db.TblPortageRowInjuries.Where(a => a.FkPortageRow == item.Id)) { db.TblPortageRowInjuries.Add(new web_db._Weighing.TblPortageRowInjury { FkInjury = iteminj.FkInjury, FkPortageRow = v.Id }); } } #endregion #region Clone images var dbdoc = new web_dbDocument.db_Context(); dbdoc.TblDocuments.RemoveRange(dbdoc.TblDocuments.Where(a => a.FkPortage == Clone.Id)); foreach (var item in dbdoc.TblDocuments.Where(a => a.FkPortage == portage.Id)) { var c = new web_dbDocument.TblDocument { Id = Guid.NewGuid(), FkP = Clone.Id, Date = item.Date, Image = item.Image, Kind = item.Kind }; dbdoc.TblDocuments.Add(c); } #endregion dbdoc.SaveChanges(); db.SaveChanges(); return(new porret[] { new porret { id = contypeclone.Id, Product = false } }); } return(null); }
public IActionResult CreateIN(Guid idtype, int kindPortage, Models.tbls.portage.portage model) { ModelState.Remove("Weight2"); ModelState.Remove("Date2date"); ModelState.Remove("Date2time"); ModelState.Remove("Customer.Mob"); ModelState.Remove("Customer.NationalCode"); ModelState.Remove("Customer.Code"); ModelState.Remove("Customer.Title"); ModelState.Remove("Customer.Id"); ModelState.Remove("FkCarTbl"); var kindPortageenum = (web_sard.Areas.ASurting.Models.tbls.portage.kindPortage.kindPortageEnum)kindPortage; if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToSardkhane || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromAnbar || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToAnbar) { ModelState.Remove("CarShMashin"); ModelState.Remove("FkCar"); ModelState.Remove("CarRanande"); ModelState.Remove("CarTell"); ModelState.Remove("Weight1IsBascul"); ModelState.Remove("Weight1"); } var typecontract = db.TblContractTypes.Find(idtype); if (typecontract.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASurting) { var conf = typecontract.ConfigASurting(); if (ModelState.IsValid) { var x = db.TblPortages.Find(model.Id); if (x == null) { model.Code = (db.TblPortages.Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.FkContracttype == idtype && a.KindCode == kindPortage).Max(a => (long?)a.Code) ?? 0) + 1; x = new web_db._Weighing.TblPortage { FkSalmali = User._getuserSalMaliDef(), Code = model.Code, Dateadd1 = DateTime.Now, FkContracttype = idtype, FkUsAdd1 = User._getuserid().Value, Id = model.Id, KindCode = kindPortage, KindTitle = Models.tbls.portage.kindPortage.listkindcontract.Find(a => a.code == kindPortage).txt, }; db.TblPortages.Add(x); } else { x.Dateedit1 = DateTime.Now; x.FkUsEdit1 = User._getuserid().Value; } x.CarMashin = model.CarMashin ?? ""; x.CarRanande = model.CarRanande ?? ""; x.CarShMashin = model.CarShMashin ?? ""; x.CarTell = model.CarTell ?? ""; x.FkCar = model.FkCar; x.CarMashin = (web_sard.Models.cl._ListCar.SingleOrDefault(a => a.Id == model.FkCar) ?? new web_db._Weighing.TblCar()).Title; x._FkContractMain = model._FkContractMain; x.FkCustomer = db.TblContracts.Find(model._FkContractMain).FkCustomer; x.Weight1 = model.Weight1; x.Weight1IsBascul = model.Weight1IsBascul; x.Txt = model.Txt; x.Date1 = model.Date1date.ToDate().AddHours(model.Date1time.Hours).AddMinutes(model.Date1time.Minutes); x.IsDel = false; x.IsPermitOk = null; x.FkUsPermit = null; x.TxtPermit = ""; var dbdoc = new web_dbDocument.db_Context(); #region captureDorbinBaskul if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.In || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.Out) { if (x.Weight1 != model.Weight1) { var z = web_sard.Models.cl.captureDorbinBaskul(); if (z != null) { dbdoc.TblDocuments.Add(new web_dbDocument.TblDocument { Date = DateTime.Now, FkP = x.Id, Id = Guid.NewGuid(), Image = z, Kind = "InBaskul", Format = "" }); } } } #endregion #region PeerSardKhane if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToSardkhane) { var xpkind = (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane ? web_sard.Areas.ASardKhane.Models.tbls.portage.kindPortage.kindPortageEnum.OutToSurt : web_sard.Areas.ASardKhane.Models.tbls.portage.kindPortage.kindPortageEnum.InFromSurt); foreach (var item in web_sard.Models.cl._ListContractType(x.FkSalmali).Where(a => a.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane)) { var xp = db.TblPortages.Find(x._FkPortagePeer); if (xp == null) { xp = new web_db._Weighing.TblPortage { FkSalmali = User._getuserSalMaliDef(), Code = model.Code, _FkPortagePeer = x.Id, Dateadd1 = DateTime.Now, FkContracttype = item.Id, FkUsAdd1 = User._getuserid().Value, Id = Guid.NewGuid(), KindCode = (int)xpkind, KindTitle = web_sard.Areas.ASardKhane.Models.tbls.portage.kindPortage.listkindcontract.Find(a => a.code == (int)xpkind).txt, }; xp.Code = (db.TblPortages.Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.FkContracttype == item.Id && a.KindCode == (int)xpkind).Max(a => (long?)a.Code) ?? 0) + 1; db.TblPortages.Add(xp); x._FkPortagePeer = xp.Id; } else { xp.Dateedit1 = DateTime.Now; xp.FkUsEdit1 = User._getuserid().Value; } xp.CarMashin = x.CarMashin ?? ""; xp.CarRanande = x.CarRanande ?? ""; xp.CarShMashin = x.CarShMashin ?? ""; xp.CarTell = x.CarTell ?? ""; xp.FkCar = x.FkCar; xp.CarMashin = (web_sard.Models.cl._ListCar.SingleOrDefault(a => a.Id == model.FkCar) ?? new web_db._Weighing.TblCar()).Title; xp.FkCustomer = x.FkCustomer; xp.Weight1 = x.Weight1; xp.Weight1IsBascul = x.Weight1IsBascul; xp.Txt = x.Txt; xp.Date1 = x.Date1; xp.IsDel = false; xp.IsPermitOk = null; xp.FkUsPermit = null; xp.TxtPermit = ""; } } #endregion #region PeerAnbar if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromAnbar || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToAnbar) { var xpkind = (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromAnbar ? web_sard.Areas.ASabad.Models.tbls.portage.kindPortage.kindPortageEnum.OutToSurt : web_sard.Areas.ASabad.Models.tbls.portage.kindPortage.kindPortageEnum.InFromSurt); foreach (var item in web_sard.Models.cl._ListContractType(x.FkSalmali).Where(a => a.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad)) { var xp = db.TblPortages.SingleOrDefault(a => a.FkContracttype == item.Id && a.Id == x._FkPortagePeer); if (xp == null) { xp = new web_db._Weighing.TblPortage { FkSalmali = User._getuserSalMaliDef(), Code = model.Code, Dateadd1 = DateTime.Now, FkContracttype = item.Id, FkUsAdd1 = User._getuserid().Value, _FkPortagePeer = x.Id, Id = Guid.NewGuid(), KindCode = (int)xpkind, KindTitle = web_sard.Areas.ASabad.Models.tbls.portage.kindPortage.listkindcontract.Find(a => a.code == (int)xpkind).txt, }; xp.Code = (db.TblPortages.Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.FkContracttype == item.Id && a.KindCode == (int)xpkind).Max(a => (long?)a.Code) ?? 0) + 1; db.TblPortages.Add(xp); x._FkPortagePeer = xp.Id; } else { xp.Dateedit1 = DateTime.Now; xp.FkUsEdit1 = User._getuserid().Value; } xp.CarMashin = x.CarMashin ?? ""; xp.CarRanande = x.CarRanande ?? ""; xp.CarShMashin = x.CarShMashin ?? ""; xp.CarTell = x.CarTell ?? ""; xp.FkCar = x.FkCar; xp.CarMashin = (web_sard.Models.cl._ListCar.SingleOrDefault(a => a.Id == model.FkCar) ?? new web_db._Weighing.TblCar()).Title; xp.FkCustomer = x.FkCustomer; xp.Weight1 = x.Weight1; xp.Weight1IsBascul = x.Weight1IsBascul; xp.Txt = x.Txt; xp.Date1 = x.Date1; xp.IsDel = false; xp.IsPermitOk = null; xp.FkUsPermit = null; xp.TxtPermit = ""; } } #endregion ViewBag.error = checkportage(x); if (((string)ViewBag.error).IsEmpty()) { db.SaveChanges(); dbdoc.SaveChanges(); _refstoreTow(x.Id); if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToSardkhane) { ASardKhane.Models.cl._refstoreTow(db, x.Id); } if (kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.InFromAnbar || kindPortageenum == Models.tbls.portage.kindPortage.kindPortageEnum.OutToAnbar) { ASabad.Models.cl._refstoreTow(db, x.Id); } return(RedirectToAction("index", new { idtype = x.FkContracttype })); } } ViewData["type"] = db.TblContractTypes.Find(idtype); ViewData["kindPortage"] = kindPortage; var intosard = false; if ((kindPortage == (int)Models.tbls.portage.kindPortage.kindPortageEnum.InFromSardkhane) || (kindPortage == (int)Models.tbls.portage.kindPortage.kindPortageEnum.OutToSardkhane)) { intosard = true; } ViewBag.contrs = (from n in db.TblContracts.Include(a => a.FkContractTypeNavigation).Include(a => a.FkCustomerNavigation) where n.FkSalmali == typecontract.FkSalmali && n.FkContractType == idtype //&& //(intosard == false ? true : (n._FkContractPeer.HasValue)) orderby n.Code ascending select n).ToList(); return(View(model)); } return(null); }