Example #1
0
        public IActionResult Store(StoreRegisterViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (_account.ExistsMailAddress(viewModel.Mail))
                {
                    ViewBag.MyMessage = false;
                    ModelState.AddModelError("Mail", "نمی توانید از این ایمیل استفاده کنید");
                }
                else
                {
                    int    userID     = 0;
                    string mobileCode = "";

                    if (_account.ExistsMobileNumber(viewModel.Mobile))
                    {
                        _account.UpdateUserRole(viewModel.Mobile);

                        userID = _account.GetUserId(viewModel.Mobile);

                        mobileCode = _account.GetUserActiveCode(viewModel.Mobile);
                    }
                    else
                    {
                        mobileCode = CodeGenerators.ActiveCode();

                        User user = new User()
                        {
                            ActiveCode = mobileCode,
                            Code       = null,
                            FullName   = null,
                            IsActive   = false,
                            Mobile     = viewModel.Mobile,
                            Password   = HashGenerators.MD5Encoding(viewModel.Password),
                            Date       = pc.GetYear(DateTime.Now).ToString("0000") + "/" + pc.GetMonth(DateTime.Now).ToString("00") +
                                         "/" + pc.GetDayOfMonth(DateTime.Now).ToString("00"),
                            RoleId = _account.GetStoreRole()
                        };

                        _account.AddUser(user);

                        userID = user.Id;
                    }

                    Store store = new Store()
                    {
                        Address          = null,
                        Desc             = null,
                        Logo             = null,
                        Mail             = viewModel.Mail,
                        MailActivate     = false,
                        MobileActivate   = false,
                        Tel              = null,
                        UserId           = userID,
                        Name             = null,
                        MailActivateCode = CodeGenerators.ActiveCode()
                    };

                    _account.AddStore(store);

                    ViewBag.MyMessage = true;

                    MessageSender sender = new MessageSender();

                    string messageBody = _render.RenderToStringAsync("_ActivateMail", store);

                    try
                    {
                        sender.Email(store.Mail, "فعالسازی فروشگاه", messageBody);
                        //sender.SMS(viewModel.Mobile, "درخواست ثبت فروشگاه انجام شد" + Environment.NewLine + "کد فعالسازی : " + mobileCode);
                    }
                    catch
                    {
                    }
                }
            }

            return(View(viewModel));
        }