Example #1
0
        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));
        }
Example #2
0
        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());
            }
        }