public async Task <ActionResult> Create(Customer inputModel)
        {
            model.inputModel = inputModel;

            if (ModelState.IsValid)
            {
                try
                {
                    var currentLoggedUserId  = User.Identity.GetUserId();
                    var currentLoggedUserRes = await UserIdentityManager
                                               .GetUserById(currentLoggedUserId);

                    inputModel.UserCreatorId = currentLoggedUserRes.registeredUser.ID;
                    inputModel.UserUpdatorId = currentLoggedUserRes.registeredUser.ID;
                    inputModel.DateCreated   = DateTime.Now;
                    inputModel.DateUpdated   = DateTime.Now;
                    inputModel.IsActive      = true;

                    await _customerRepo.Create(inputModel);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(View("Create", model));
                }
            }
            return(View("Create", model));
        }
        public ActionResult Create(CustomerVM cust)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(cust));
                }
                var customer = _mapper.Map <Customer>(cust);
                customer.Registered = DateTime.Now;
                var isSuccess = _repo.Create(customer);
                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Check for Information");
                    return(View(cust));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch

            {
                ModelState.AddModelError("", "Check for Information");
                return(View());
            }
        }
        public Customer Create(CustomerViewModel customer)
        {
            Customer newCustomer = new Customer()
            {
                F_Name     = customer.F_Name,
                L_Name     = customer.L_Name,
                E_mail     = customer.E_mail,
                CreditCard = customer.CreditCard
            };

            return(_customerRepo.Create(newCustomer));
        }
示例#4
0
 public async virtual Task Create(Customer customer)
 {
     // Save to Repo first
     await _customerRepo.Create(customer);
 }