public IActionResult AddCustomerData(AddCustomerDto customerDto) { TvCheckIn tvCheckIn = new TvCheckIn { Failure = customerDto.Failure, CustomerData = null, CustomerDataId = 0, DateIn = customerDto.DateIn, Id = 0, Returned = customerDto.Returned, TvCheckOut = null }; CustomerData customerData = new CustomerData { Id = 0, Name = customerDto.Name, PhoneNumber = customerDto.PhoneNumber, TvBrand = customerDto.TvBrand, TvCheckIns = new [] { tvCheckIn }, TvInch = customerDto.TvInch }; _dbContext.Add(customerData); _dbContext.SaveChanges(); return(Ok()); }
public async Task <ICommandResult> AddCustomerAsync(AddCustomerDto addCustomerDto) { var user = new ApplicationUser { UserName = addCustomerDto.Email, Email = addCustomerDto.Email }; var result = await _userManager.CreateAsync(user, addCustomerDto.Password); if (result.Succeeded) { var createCustomerCommand = Mapper.Map <CreateCustomerCommand>(addCustomerDto); var commandResult = _customerCommandHandler.Handle(createCustomerCommand); if (commandResult.Success) { var customer = (Customer)commandResult.Data; user.CustomerId = customer.Id; await _userManager.UpdateAsync(user); } return(commandResult); } return(new CommandResult(false, result.Errors.Select(e => e.Description))); }
public async Task <IActionResult> AddAsync([FromBody] AddCustomerDto addItem, CancellationToken cancellationToken) { if (await this._customerService.AddAsync(addItem, cancellationToken)) { return(StatusCode(StatusCodes.Status200OK)); } return(StatusCode(StatusCodes.Status400BadRequest, new ErrorDetailDto("Cannot add customer"))); }
public async Task <ServiceResponse <GetCustomerDto> > createCustomer(AddCustomerDto customer) { ServiceResponse <GetCustomerDto> response = new ServiceResponse <GetCustomerDto>(); Customer Customer = _mapper.Map <Customer>(customer); Customer.User = await _context.Users.FirstOrDefaultAsync(c => c.Id == GetUserId()); await _context.AddAsync(Customer); await _context.SaveChangesAsync(); response.Data = _mapper.Map <GetCustomerDto>(Customer); return(response); }
public ActionResult Create(AddCustomerDto customerDto) { var customer = new Customer(); var id = Convert.ToInt32(Session["UserId"]); customer.FirstName = customerDto.FirstName; customer.LastName = customerDto.LastName; customer.CellPhone = customerDto.CellPhone; customer.Email = customerDto.Email; customer.UserId = id; _customerRepository.CreateCustomer(customer); return(RedirectToAction("List")); }
public async Task <ActionResult <AddCustomerDto> > Create([FromBody] AddCustomerDto dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } dto.Id = Guid.NewGuid().ToString(); var customer = new Customer(dto.Id, dto.Name); customer.SetAddress(dto.AddressLine1, dto.AddressLine2, dto.City, dto.State, dto.Country, dto.PostCode); await _customerRepository.AddAsync(customer) .AnyContext(); return(CreatedAtAction(nameof(GetById), new { id = dto.Id }, dto)); }
public async Task <IActionResult> Register(AddCustomerDto addCustomerDto) { try { if (ModelState.IsValid) { var commandResult = await _customerAppService.AddCustomerAsync(addCustomerDto); if (commandResult.Success) { return(Ok(commandResult)); } return(BadRequest(commandResult)); } } catch (System.Exception exception) { throw; } return(Ok()); }
public IActionResult Add(AddCustomerDto customerDto) { if (ModelState.IsValid) { Customer customer = _mapper.Map <Customer>(customerDto); _customerRepository.Add(customer); foreach (int cType in customerDto.CustomerTypes) { CustomerTypeCustomer customerTypeCustomer = new CustomerTypeCustomer { Customer = customer, CustomerTypeId = cType }; _customerTypeCustomerRepository.Add(customerTypeCustomer); } return(RedirectToAction("Index")); } TempData["CustomerTypes"] = _customerTypes; return(View(customerDto)); }
public ActionResult Create() { var customerDto = new AddCustomerDto(); return(View(customerDto)); }
public async Task <IActionResult> createCustomer(AddCustomerDto newCustomer) { return(Ok(await _customerService.createCustomer(newCustomer))); }