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 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()); } }