public static Customer ConvertToEntity(this CustomerAddModel addModel)
 => new Customer
 {
     Name     = new FullName(addModel.FirstName, addModel.MiddleName, addModel.LastName),
     Email    = addModel.Email,
     Password = addModel.Password
 };
        public async Task <int> AddAsync(CustomerAddModel customer)
        {
            //CustomerNo must be unique
            var checkData = await _context.Customers.Where(c => c.CustomerNo == customer.CustomerNo).ToListAsync();

            if (checkData.Count > 0)
            {
                throw new ExpectException("The data which CustomerNo equal to '" + customer.CustomerNo + "' already exist in system");
            }

            //Get UserInfo
            var user = _loginUser.GetLoginUserInfo();

            var model = new Customer
            {
                CustomerName = customer.CustomerName,
                CustomerNo   = customer.CustomerNo,
                Creator      = user.UserName,
                CreateDate   = DateTime.Now
            };

            _context.Customers.Add(model);

            await _context.SaveChangesAsync();

            return(model.CustomerId);
        }
Beispiel #3
0
        public ActionResult Add(CustomerAddModel model)
        {
            JsonResultModel result = new JsonResultModel();

            try
            {
                Validate validate = new Validate();
                validate.CheckObjectArgument <CustomerAddModel>("model", model);
                if (validate.IsFailed)
                {
                    result.BuilderErrorMessage(validate.ErrorMessages);
                    return(Json(result));
                }
                model.PostValidate(ref validate);
                if (validate.IsFailed)
                {
                    result.BuilderErrorMessage(validate.ErrorMessages);
                    return(Json(result));
                }
                result.Data   = this.customerService.Add(model.Name, model.Nickname, model.Mobile, model.Address, string.Empty, model.GroupId, this.Session["Mobile"].ToString());
                result.Result = true;
            }
            catch (EasySoftException ex)
            {
                result.BuilderErrorMessage(ex.Message);
            }
            catch (Exception ex)
            {
                result.BuilderErrorMessage(ex.Message);
            }
            return(Json(result));
        }
        public async Task <int> AddAsync(CustomerAddModel model)
        {
            var customer = CustomerFactory.Create(model, _userId);
            await _customerRepository.AddAsync(customer);

            await _unitOfWork.SaveChangesAsync();

            return(customer.Id);
        }
        public async Task <IActionResult> AddAsync([FromBody] CustomerAddModel mCustomer)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelStateError()));
            }

            int customerId = await _customerRepository.AddAsync(mCustomer);

            return(CreatedAtRoute("GetByCustomerIdAsync", new { controller = "Customers", customerId = customerId }, mCustomer));
        }
        public static Customer Create(CustomerAddModel model, string userId)
        {
            var customer = new Customer
            {
                FirstName  = model.FirstName,
                MiddleName = model.MiddleName,
                LastName   = model.LastName,
                Phone      = model.Phone,
                Email      = model.Email,

                CreatedBy = userId ?? "0",
                CreatedOn = Utility.GetDateTime(),
                Status    = Constants.RecordStatus.Active
            };

            return(customer);
        }
Beispiel #7
0
        public HttpResponseMessage Add([FromBody] CustomerAddModel addModel)
        {
            if (!ModelState.IsValid)
            {
                var validationErrors = ModelState.Values
                                       .SelectMany(_ => _.Errors.Select(x => x.ErrorMessage));
                return(Request.CreateResponse((HttpStatusCode)422, validationErrors));
            }
            var added = Service.Add(addModel);

            if (added)
            {
                return(Request.CreateResponse(HttpStatusCode.Created));
            }
            return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            //return Request.CreateResponse(418, "I'm a teapot");
        }
Beispiel #8
0
        public DbResponse Add(CustomerAddModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.UserName))
                {
                    return(new DbResponse(false, "Invalid Data"));
                }

                _db.Customer.Add(model);
                _db.SaveChanges();

                return(new DbResponse(true, "Success"));
            }
            catch (Exception e)
            {
                return(new DbResponse(false, e.Message));
            }
        }
        public async Task <IActionResult> Add([FromBody] CustomerAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorList()));
            }

            if (await _customerManager.IsEmailExistsAsync(model.Email))
            {
                return(BadRequest("Another customer with same email already exists"));
            }

            try
            {
                var customerId = await _customerManager.AddAsync(model);

                return(Ok(customerId));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Beispiel #10
0
        public async Task <DbResponse <IdentityUser> > MobileSignUpAsync(CustomerMobileSignUpModel model)
        {
            try
            {
                long timeStepMatched;
                var  verify = OtpServiceSingleton.Instance.Totp.VerifyTotp(model.Code, out timeStepMatched, window: null);
                if (model.MobileNumber != OtpServiceSingleton.Instance.PhoneNunber)
                {
                    return(new DbResponse <IdentityUser>(false, "Mobile number not match"));
                }
                if (!verify)
                {
                    return(new DbResponse <IdentityUser>(false, "Invalid Code"));
                }

                //Identity Create
                var user = new IdentityUser {
                    UserName = model.MobileNumber
                };
                var password = model.Password;
                var result   = await _userManager.CreateAsync(user, password).ConfigureAwait(false);

                if (!result.Succeeded)
                {
                    return(new DbResponse <IdentityUser>(false, result.Errors.FirstOrDefault()?.Description));
                }

                await _userManager.AddToRoleAsync(user, UserType.Customer.ToString()).ConfigureAwait(false);

                var customer = new CustomerAddModel
                {
                    UserName = model.MobileNumber
                };

                _db.Customer.Add(customer);
                _db.SaveChanges();
                #region SMS Code

                var textSms = $"You have registered Successfully , Your Id: {model.MobileNumber}";

                var massageLength = SmsValidator.MassageLength(textSms);
                var smsCount      = SmsValidator.TotalSmsCount(textSms);

                var smsProvider = new SmsProviderBuilder();

                var smsBalance = smsProvider.SmsBalance();
                if (smsBalance < smsCount)
                {
                    return(new DbResponse <IdentityUser>(true, "Success, No SMS Balance", user));
                }

                var providerSendId = smsProvider.SendSms(textSms, model.MobileNumber);

                if (!smsProvider.IsSuccess)
                {
                    return(new DbResponse <IdentityUser>(true, smsProvider.Error, user));
                }

                #endregion

                return(new DbResponse <IdentityUser>(true, "Success", user));
            }
            catch (Exception e)
            {
                return(new DbResponse <IdentityUser>(false, e.Message));
            }
        }
Beispiel #11
0
        public ActionResult Add(string source)
        {
            CustomerAddModel model = new CustomerAddModel(source);

            return(View(model));
        }