Exemple #1
0
        public ActionResult CreateRequest(CompanyRegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return(JsonValidationError());
            }
            if (!string.IsNullOrEmpty(model.Password))
            {
                if (!Regex.IsMatch(model.Password, SiteUtils.GetPasswordRegex()))
                {
                    ModelState.AddModelError("Password", "Password does not meet policy!");
                    return(JsonValidationError());
                }
            }
            model.Mobile    = SiteUtils.GenerateEncodedString(model.Mobile);
            model.Telephone = SiteUtils.GenerateEncodedString(model.Telephone);
            var user = new CustomerModel
            {
                Email            = Sanitizer.GetSafeHtmlFragment(model.Email),
                FirstName        = Sanitizer.GetSafeHtmlFragment(model.FirstName),
                LastName         = Sanitizer.GetSafeHtmlFragment(model.LastName),
                Mobile           = Sanitizer.GetSafeHtmlFragment(model.Mobile),
                PostCode         = Sanitizer.GetSafeHtmlFragment(model.PostCode),
                Telephone        = Sanitizer.GetSafeHtmlFragment(model.Telephone),
                Title            = Sanitizer.GetSafeHtmlFragment(model.Title),
                BusinessType     = Sanitizer.GetSafeHtmlFragment(model.BusinessType),
                CompanyName      = Sanitizer.GetSafeHtmlFragment(model.CompanyName),
                RegisteredNumber = Sanitizer.GetSafeHtmlFragment(model.RegisteredNumber),
                Password         = Sanitizer.GetSafeHtmlFragment(model.Password),
                IsRegistered     = true,
                Address          = new CompanyAddress
                {
                    Address1 = Sanitizer.GetSafeHtmlFragment(model.Address1),
                    Address2 = Sanitizer.GetSafeHtmlFragment(model.Address2),
                    City     = Sanitizer.GetSafeHtmlFragment(model.City),
                    State    = Sanitizer.GetSafeHtmlFragment(model.State),
                    Country  = Sanitizer.GetSafeHtmlFragment(model.Country),
                    PostCode = Sanitizer.GetSafeHtmlFragment(model.PostCode)
                },
            };

            user.Mobile    = SiteUtils.GenerateDecodeString(user.Mobile);
            user.Telephone = SiteUtils.GenerateDecodeString(user.Telephone);

            var result = _customerRepository.Register(user);

            if (result.Result.IsValid)
            {
                return(JsonSuccess(result.Result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                ModelState.AddModelError("Error", "Registration Request failed!");
                return(JsonValidationError());
            }
        }
Exemple #2
0
        public ActionResult ConvertRequest(ConvertCompanyAccountModel model)
        {
            if (!ModelState.IsValid)
            {
                return(JsonValidationError());
            }
            model.Mobile    = SiteUtils.GenerateEncodedString(model.Mobile);
            model.Telephone = SiteUtils.GenerateEncodedString(model.Telephone);
            var user = new CustomerModel
            {
                Email            = Sanitizer.GetSafeHtmlFragment(model.Email),
                FirstName        = Sanitizer.GetSafeHtmlFragment(model.FirstName),
                LastName         = Sanitizer.GetSafeHtmlFragment(model.LastName),
                Mobile           = model.Mobile,
                PostCode         = Sanitizer.GetSafeHtmlFragment(model.PostCode),
                Telephone        = model.Telephone,
                Title            = Sanitizer.GetSafeHtmlFragment(model.Title),
                BusinessType     = Sanitizer.GetSafeHtmlFragment(model.BusinessType),
                CompanyName      = Sanitizer.GetSafeHtmlFragment(model.CompanyName),
                RegisteredNumber = Sanitizer.GetSafeHtmlFragment(model.RegisteredNumber),
                IsRegistered     = true,
                Address          = new CompanyAddress
                {
                    Address1 = Sanitizer.GetSafeHtmlFragment(model.Address1),
                    Address2 = Sanitizer.GetSafeHtmlFragment(model.Address2),
                    City     = Sanitizer.GetSafeHtmlFragment(model.City),
                    State    = Sanitizer.GetSafeHtmlFragment(model.State),
                    Country  = Sanitizer.GetSafeHtmlFragment(model.Country),
                    PostCode = Sanitizer.GetSafeHtmlFragment(model.PostCode)
                },
            };

            user.Mobile    = SiteUtils.GenerateDecodeString(user.Mobile);
            user.Telephone = SiteUtils.GenerateDecodeString(user.Telephone);
            user.IsConvertCompanyRequest = true;

            var result = _customerRepository.Register(user);

            if (result.Result.IsValid)
            {
                return(JsonSuccess(result.Result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                ModelState.AddModelError("Error", "Registration Request failed!");
                return(JsonValidationError());
            }
        }
        public ActionResult SaveCustomerAddress(AddressModel model)
        {
            var resp = new BoolResponse();

            if (!ModelState.IsValid)
            {
                return(JsonValidationError());
            }
            model.MobileNo = SiteUtils.GenerateEncodedString(model.MobileNo);
            model.PhoneNo  = SiteUtils.GenerateEncodedString(model.PhoneNo);
            var addressModel = new AddressModel
            {
                Address1    = Sanitizer.GetSafeHtmlFragment(model.Address1),
                Address2    = Sanitizer.GetSafeHtmlFragment(model.Address2),
                Address3    = Sanitizer.GetSafeHtmlFragment(model.Address3),
                City        = Sanitizer.GetSafeHtmlFragment(model.City),
                Country     = Sanitizer.GetSafeHtmlFragment(model.Country),
                CountryCode = Sanitizer.GetSafeHtmlFragment(model.CountryCode),
                CompanyName = Sanitizer.GetSafeHtmlFragment(model.CompanyName),
                CustomerId  = Sanitizer.GetSafeHtmlFragment(model.CustomerId),
                FirstName   = Sanitizer.GetSafeHtmlFragment(model.FirstName),
                LastName    = Sanitizer.GetSafeHtmlFragment(model.LastName),
                Id          = Sanitizer.GetSafeHtmlFragment(model.Id),
                MobileNo    = Sanitizer.GetSafeHtmlFragment(model.MobileNo),
                PhoneNo     = Sanitizer.GetSafeHtmlFragment(model.PhoneNo),
                PostCode    = Sanitizer.GetSafeHtmlFragment(model.PostCode),
                State       = Sanitizer.GetSafeHtmlFragment(model.State),
                Title       = Sanitizer.GetSafeHtmlFragment(model.Title),
                IsDefault   = model.Id == null ? true : model.IsDefault
            };

            addressModel.MobileNo = SiteUtils.GenerateDecodeString(addressModel.MobileNo);
            addressModel.PhoneNo  = SiteUtils.GenerateDecodeString(addressModel.PhoneNo);
            if (addressModel.Id == null || addressModel.Id == "")
            {
                addressModel.CustomerId = _sessionContext.CurrentUser.UserId.ToString();
                var response = _customerRepository.SaveCustomerAddress(addressModel);
                resp.IsValid = response.Result;
            }
            else
            {
                var response = _customerRepository.UpdateCustomerAddress(Sanitizer.GetSafeHtmlFragment(addressModel.Id), addressModel);
                resp.IsValid = response.Result;
            }
            return(JsonSuccess(resp, JsonRequestBehavior.AllowGet));
        }