public async Task <IActionResult> Edit(web_CusDB.tblCus model) { if (model.CodeMelli.IsCodemeli() == false) { ModelState.AddModelError("CodeMelli", "کد ملی اشتباه است"); } if (ModelState.IsValid) { var db = new web_CusDB.db_Context(); var us = db.TblCustomers.Single(a => a.Id == User._getuserId()); us.Name = model.Name; us.CodeMelli = model.CodeMelli; us.Addras = model.Addras; us.CodeCusMainSystem = us.checkCodeCusMain().Code; db.SaveChanges(); await LoginAuth._loginAsync(this.HttpContext, us); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult Confirm(web_CusDB.tblReqContractRow model, bool sms, string Txtsms, Guid[] mahsulss, web_CusDB.tblReqContractRow.ResEnum kind) { var dbcus = new web_CusDB.db_Context(); var db = new web_db.sardweb_Context(); var x = dbcus.tblReqContracts.Include(a => a.tblReqContractRows) .Include(a => a.tblCus).SingleOrDefault(a => a.Id == model.Id); x._LasttblReqContractRows = x.tblReqContractRows.OrderByDescending(a => a.Date).First(); var z = db.TblProducts.Where(a => mahsulss.Contains(a.Id)).Select(a => a.Title).ToList(); z.AddRange(db.TblPackings.Where(a => mahsulss.Contains(a.Id)).Select(a => a.Title).ToList()); model.CodeMahsuls = mahsulss.ToJson(); model.Mahsuls = string.Join(',', z); dbcus.tblReqContractRows.Add(new web_CusDB.tblReqContractRow { Id = Guid.NewGuid(), CodeMahsuls = model.CodeMahsuls, Mahsuls = model.Mahsuls, Date = DateTime.Now, ResDate = DateTime.Now, ResTxt = model.ResTxt, ResUserId = User._getuserid(), TblReqContractId = x.Id, Vaziat = kind, WeightCount = model.WeightCount }); //var row = db.tbl.Find(id); //row.WeightConfirm = WeightConfirm; //row.KindQueu = kind; //row.TxtReq = TxtReq; if (sms && Txtsms.IsEmpty() == false && Txtsms.Length > 5) { Models.cl._listSmsForSend.Add(new Models.cl.SmsForSend { number = x.tblCus.Mob, txt = Txtsms }); } dbcus.SaveChanges(); return(RedirectToAction(nameof(List))); }
public IActionResult Edit() { var db = new web_CusDB.db_Context(); var us = db.TblCustomers.Single(a => a.Id == User._getuserId()); us.CodeCusMainSystem = us.checkCodeCusMain().Code; if (us.CodeCusMainSystem.HasValue) { db.SaveChanges(); } if (User._getuserIsProfileOK() && us.CodeCusMainSystem.HasValue) { return(RedirectToAction("Index")); } return(View(us)); }
public IActionResult List(web_db._Weighing.TblContractType.KindCotractTypeEnum kindcontract = web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane, web_CusDB.tblReqContractRow.ResEnum id = web_CusDB.tblReqContractRow.ResEnum.Save) { ViewBag.kindcontract = kindcontract; ViewBag.id = id; var dbcus = new web_CusDB.db_Context(); { var xx = dbcus.tblReqContracts.Include(s => s.tblReqContractRows).Where(a => a.tblReqContractRows.Any() == false); if (xx.Any()) { dbcus.tblReqContracts.RemoveRange(xx); dbcus.SaveChanges(); } } var x = dbcus.tblReqContracts.Include(a => a.tblReqContractRows).OrderBy(a => a.DateLast).Include(a => a.tblCus) .Where(a => a.KindContract == kindcontract && a.tblReqContractRows. OrderByDescending(s => s.Date).First().Vaziat == id).ToList(); foreach (var item in x) { item._LasttblReqContractRows = item.tblReqContractRows.OrderByDescending(a => a.Date).First(); } return(View(x)); }
public IActionResult SyncCusSystem() { { using (var dbCus = new web_CusDB.db_Context()) { using (var db = new web_db.sardweb_Context()) { long code = (dbCus.tblReqContracts.Max(a => (long?)a.Code) ?? 0); foreach (var item in db.TblQueus.Where(a => (a.KindQueu == web_db._queu.TblQueu.QueuEnum.Save) || (a.KindQueu == web_db._queu.TblQueu.QueuEnum.IsActive)).Take(100)) { code++; var con = dbCus.tblReqContracts.Find(item.Id); if (con == null) { var cus = dbCus.TblCustomers.SingleOrDefault(a => a.Mob == item.mob && a.CodeMelli == item.codemeli); if (cus == null) { cus = new web_CusDB.tblCus { CodeMelli = item.codemeli, dateAdd = item.date, Addras = item.Addras, Id = Guid.NewGuid(), Mob = item.mob, Name = item.Name, }; dbCus.TblCustomers.Add(cus); } con = new web_CusDB.tblReqContract { Code = (code), DateAdd = item.date, ContractId = item.ContractID, KindContract = web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane, Id = item.Id, IsEdit = false, tblCusId = cus.Id, DateLast = DateTime.Now, }; dbCus.tblReqContracts.Add(con); dbCus.tblReqContractRows.Add(new web_CusDB.tblReqContractRow { CodeMahsuls = item.CodeMahsuls, Date = item.date, Id = Guid.NewGuid(), Vaziat = web_CusDB.tblReqContractRow.ResEnum.Save, WeightCount = item.Weight ?? 0, TblReqContractId = con.Id, Mahsuls = item.Mahsuls, }); // db.Remove(item); } } db.SaveChanges(); dbCus.SaveChanges(); } } } return(RedirectToAction("Index")); }
public IActionResult New(web_db._Weighing.TblContractType.KindCotractTypeEnum Kind, web_CusDB.tblReqContractRow model, List <Guid> Product, List <Guid> Packing) { var dbweb = new web_db.sardweb_Context(); if (Kind == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane) { if (!Product.Any()) { ModelState.AddModelError("CodeMahsuls", "محصولات انتخاب نشده است"); } if (!Packing.Any()) { ModelState.AddModelError("CodeMahsuls", "سبد انتخاب نشده است"); } } else if (Kind == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad) { if (!Packing.Any()) { ModelState.AddModelError("CodeMahsuls", "سبد انتخاب نشده است"); } } if (model.WeightCount < 10) { ModelState.AddModelError("WeightCount", "مقدار اشتباه است"); } if (ModelState.IsValid) { var db = new web_CusDB.db_Context(); var row = new web_CusDB.tblReqContract { Code = (db.tblReqContracts.Max(a => (long?)a.Code) ?? 0) + 1, DateAdd = DateTime.Now, DateLast = DateTime.Now, Id = Guid.NewGuid(), KindContract = Kind, tblCusId = User._getuserId().Value, }; db.tblReqContracts.Add(row); var p = new List <Guid>(); p.AddRange(Product); p.AddRange(Packing); var z = dbweb.TblProducts.Where(a => Product.Contains(a.Id)).Select(a => a.Title).ToList(); z.AddRange(dbweb.TblPackings.Where(a => Packing.Contains(a.Id)).Select(a => a.Title).ToList()); db.tblReqContractRows.Add(new web_CusDB.tblReqContractRow { CodeMahsuls = p.ToJson(), Date = row.DateLast, Id = Guid.NewGuid(), Vaziat = web_CusDB.tblReqContractRow.ResEnum.Save, WeightCount = model.WeightCount, TblReqContractId = row.Id, Mahsuls = string.Join(',', z) }); db.SaveChanges(); var dbmain = new web_db.sardweb_Context(); sms sms = new sms() { numfrom = dbmain.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Main_NumSms).Value, password = dbmain.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Main_PassSms).Value, username = dbmain.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Main_UserSms).Value, }; var us = db.TblCustomers.Find(User._getuserId().Value); sms.sendsmsAsync(us.Mob, (dbmain.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Main_SherkatName) ?? new web_db.TblConf()).Value + @$ " درخواست شما با کد " + row.Code.ToString() + " ثبت گردید"); return(RedirectToAction("Index")); } if (Kind == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane) { ViewBag.listPacking = dbweb.TblPackings.AsEnumerable().Where(a => a.ForContractType().Contains(web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane) && a.IsActive == true) .OrderBy(a => a.Code).ToList(); } else if (Kind == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad) { ViewBag.listPacking = dbweb.TblPackings.AsEnumerable().Where(a => a.ForContractType().Contains(web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad) && a.IsActive == true) .OrderBy(a => a.Code).ToList(); } ViewBag.listProduct = dbweb.TblProducts.Where(a => a.IsActive).OrderBy(a => a.Ord).ToList(); ViewBag.US_WeightMax = (dbweb.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.US_WeightMax) ?? new web_db.TblConf()).Value; ViewBag.US_WeightMin = (dbweb.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.US_WeightMin) ?? new web_db.TblConf()).Value; ViewBag.US_WeightVahed = (dbweb.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.US_WeightVahed) ?? new web_db.TblConf()).Value; ViewBag.US_WeightZarib = (dbweb.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.US_WeightZarib) ?? new web_db.TblConf()).Value; ViewBag.Kind = Kind; var Kinds = dbweb.TblContractTypes.Where(a => a.FkSalmali == dbweb.TblSalMalis.SingleOrDefault(a => a.IsOpen && a.IsOrginal).Id).Select(a => a.KindCotractType).Distinct().ToList(); Kinds.Remove(web_db._Weighing.TblContractType.KindCotractTypeEnum.ABaskul); ViewBag.kinds = Kinds; return(View(model)); }
public async Task <IActionResult> Login(string mob, string code) { if (mob.IsEmpty()) { return(View( )); } if (mob.IsMobile()) { ViewBag.mob = mob; var db = new web_CusDB.db_Context(); var us = db.TblCustomers.SingleOrDefault(a => a.Mob == mob); if (code.IsEmpty()) { if (this.Request.googleRecapch3Check(web_CusDB.stat.CapchSecretKey) == false) { ViewBag.mob = null; ViewBag.err = "لطفاً تایید کنید که ربات نیستید."; ModelState.AddModelError(string.Empty, "لطفاً تایید کنید که ربات نیستید."); return(View()); } if (us == null) { us = new web_CusDB.tblCus { Id = Guid.NewGuid(), Mob = mob, dateAdd = DateTime.Now, Addras = "", CodeMelli = "", Name = "", CodeCusMainSystemAcc = "" }; db.TblCustomers.Add(us); } if (us._DateCodeSms.GetValueOrDefault().AddMinutes(2) > DateTime.Now) { ViewBag.txt = "کد قبلا برای شما ارسال گردیده است"; return(View()); } var dbmain = new web_db.sardweb_Context(); sms sms = new sms() { numfrom = dbmain.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Main_NumSms).Value, password = dbmain.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Main_PassSms).Value, username = dbmain.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Main_UserSms).Value, }; us._CodeSMS = new Random().Next(1000, 99999); us._DateCodeSms = DateTime.Now; db.SaveChanges(); sms.sendsmsAsync(mob, (dbmain.TblConf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.Main_SherkatName) ?? new web_db.TblConf()).Value + @$ " کد ورود به سایت: " + us._CodeSMS.ToString()); ViewBag.txt = "کد برای شما ارسال گردید"; return(View()); } else { if (us._CodeSMS.ToString() == code) { us.CodeCusMainSystem = web_CusDB.tblCus.checkCodeCusMain(us).Code; us.dateLast = DateTime.Now; db.SaveChanges(); await LoginAuth._loginAsync(HttpContext, us); return(RedirectToAction("index", "home")); } else { ViewBag.txt = "کد ارسالی اشتباه است"; return(View()); } } } else { ViewBag.txt = "شماره موبایل اشتباه است"; return(View()); } }
public IActionResult Edit(web_CusDB.tblReqContract model, Guid[] mahsulss) { var dbcus = new web_CusDB.db_Context(); var db = new web_db.sardweb_Context(); if (ModelState.IsValid) { var row = dbcus.tblReqContracts.Find(model.Id); var rowcus = dbcus.TblCustomers.SingleOrDefault(a => model.tblCus.CodeMelli == a.CodeMelli); { if (rowcus == null) { if (row != null) { rowcus = dbcus.TblCustomers.Find(row.tblCusId); } else { rowcus = new web_CusDB.tblCus { Id = Guid.NewGuid(), dateAdd = DateTime.Now }; dbcus.TblCustomers.Add(rowcus); } } rowcus.CodeMelli = model.tblCus.CodeMelli; rowcus.Addras = model.tblCus.Addras; rowcus.Mob = model.tblCus.Mob; rowcus.Name = model.tblCus.Name; } if (row == null) { row = new web_CusDB.tblReqContract { Id = Guid.NewGuid(), Code = (dbcus.tblReqContracts.Max(a => (long?)a.Code) ?? 0) + 1, DateAdd = DateTime.Now, KindContract = model.KindContract, }; dbcus.tblReqContracts.Add(row); var z = db.TblProducts.Where(a => mahsulss.Contains(a.Id)).Select(a => a.Title).ToList(); z.AddRange(db.TblPackings.Where(a => mahsulss.Contains(a.Id)).Select(a => a.Title).ToList()); model._LasttblReqContractRows.CodeMahsuls = mahsulss.ToJson(); model._LasttblReqContractRows.Mahsuls = string.Join(',', z); var rowrow = new web_CusDB.tblReqContractRow { Id = Guid.NewGuid(), CodeMahsuls = model._LasttblReqContractRows.CodeMahsuls, Mahsuls = model._LasttblReqContractRows.Mahsuls, Date = DateTime.Now, Vaziat = web_CusDB.tblReqContractRow.ResEnum.Save, WeightCount = model._LasttblReqContractRows.WeightCount, ResUserId = User._getuserid(), TblReqContractId = row.Id }; dbcus.tblReqContractRows.Add(rowrow); } row.tblCusId = rowcus.Id; // var z = db.TblProducts.Where(a => mahsulss.Contains(a.Id)).Select(a => a.Title).ToList(); // z.AddRange(db.TblPackings.Where(a => mahsulss.Contains(a.Id)).Select(a => a.Title).ToList()); // row.Addras = model.Addras; // row.Mahsuls = string.Join(',', z); // row.Weight = model.Weight; // row.codemeli = model.codemeli; // row.KindQueu = web_db._queu.TblQueu.QueuEnum.Save; // row.CodeMahsuls = model.CodeMahsuls; // row.Name = model.Name; // row.Txt = model.Txt; dbcus.SaveChanges(); return(RedirectToAction(nameof(List))); } return(View()); }