public async Task <IActionResult> Create([Bind("Id,Name,Phone,Address,Email,Active,Rowversion, SelectedCustomerDiscountViewModel")] CECustomerViewModel cEcustomerViewModel) { CustomerViewModel customerViewModel = CustomerMapper.Map(cEcustomerViewModel); if (ModelState.IsValid) { try { await _customerService.AddAsync(CustomerMapper.Map(customerViewModel)).ConfigureAwait(false); return(RedirectToAction(nameof(Index))); } catch (Exception) { var dbcustomer = CustomerMapper.Map((customerViewModel)); var customerDiscountTypeDtos = await _customerService.GetAllCustomerDiscountType().ConfigureAwait(false); IEnumerable <CustomerDiscountTypeViewModel> customerDiscountTypeViewModels = CustomerMapper.Map(customerDiscountTypeDtos); cEcustomerViewModel.CustomerDiscountTypeViewModels = customerDiscountTypeViewModels.ToList(); ModelState.AddModelError(string.Empty, "Email eller Telefonnummer er brugt af en anden"); return(View(cEcustomerViewModel)); } } return(View(customerViewModel)); }
public async Task GivenAName_AddCustomer() { var result = await _customerService.AddAsync(new Business.Model.CustomerModel { Created = DateTime.Now, Modified = DateTime.Now, CreatedBy = "Gabi", ModifiedBy = "Gabi", DOB = DateTime.Now, FirstName = "Gabriel", Surname = "Renom", Telephone = "077823823" }); Assert.AreEqual(result.FirstName, "Gabriel"); }
private async void btnSave_Click(object sender, EventArgs e) { try { ValidateFields(); var customer = new CustomerModel(); customer.FullName = txtFullName.Text; customer.Address = txtAddress.Text; customer.ContactNumber = txtContactNum.Text; //edit if (_id > 0) { await _customerService.EditAsync(_id, customer); } else { //add await _customerService.AddAsync(customer); } this.Close(); } catch (CustomBaseException ex) { MetroMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MetroMessageBox.Show(this, ex.ToString()); } }
// POST api/values public async Task <HttpResponseMessage> Post(CustomerModel customer) { CustomerModel result = null; try { result = await _customerService.AddAsync(customer); } catch (HttpRequestException ex) { Trace.TraceError(ex.Message); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } catch (SecurityException ex) { Trace.TraceError(ex.Message); return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, ex.Message)); } catch (Exception ex) { Trace.TraceError(ex.Message); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } return(Request.CreateResponse(HttpStatusCode.Created, result, new JsonMediaTypeFormatter())); }
public async Task <IActionResult> Add(CustomerModel crmdl) { var customer = new Customer(); customer.Name = crmdl.CustomerName; customer.Adress = crmdl.Adress; customer.PhoneNumber = crmdl.PhoneNumber; customer.Surname = crmdl.CustomerSurname; customer.TRIDNo = crmdl.TRIDNO; customer.PasportNumber = crmdl.PasaportNumber; customer.UserID = crmdl.UserID; customer.BirthDate = crmdl.BirthDate; customer.RegisterDate = DateTime.Now; customer.isCorporate = customer.isTRIDVerified = false; customer.isTRCitizen = true; var operationresult = await customerService.AddAsync(customer); if (operationresult) { return(RedirectToAction("Index")); } return(View(crmdl)); }
public async Task <IActionResult> Post(Customer customer) { _CustomerService.AddAsync(customer); return(Ok()); }
public async Task <IActionResult> AddCustomer([FromBody] CustomerForAddDto customerForAddDto) { var customer = _mapper.Map <Customer>(customerForAddDto); await _customerService.AddAsync(customer); return(Ok()); }
public async Task <IActionResult> Post([FromBody] CustomerModel customerModel) { _iLogger.LogInformation($"Controller : {this.GetControllerName()} , Action {this.GetActionName()} : => Visited at {DateTime.UtcNow.ToLongTimeString()}"); var createdCustomer = await _iCustomerService.AddAsync(customerModel); return(CreatedAtAction(nameof(GetById), new { id = createdCustomer.Id }, createdCustomer.Id)); }
public async Task <IResult <CustomerViewModel> > AddAsync(CustomerViewModel customerViewModel) { var customer = _mapper.Map <Customer>(customerViewModel); var customerResult = await _customerService.AddAsync(customer); customerViewModel = _mapper.Map <CustomerViewModel>(customerResult.Data); return(new SuccessResult <CustomerViewModel>(customerViewModel)); }
public async Task <IActionResult> Post([FromBody] CustomerInput customerInput) { var customer = _mapper.Map <Customer>(customerInput); var created = await _customerService.AddAsync(customer); return(Created(_mapper.Map <CustomerOutput>(created))); }
public async Task <IActionResult> AddCustomer([FromBody] CustomerForCreationDto model) { var customer = _mapper.Map <Customer>(model); var customerAdded = _mapper.Map <CustomerDto>(await _customerService.AddAsync(customer)); return(CreatedAtRoute("GetCustomer", new { id = customerAdded.CustomerID }, customerAdded)); }
public async Task <Customer> AddAsync(CustomerViewModel customerViewModel) { var result = await _customerService.AddAsync(_mapper.Map <Customer>(customerViewModel)); if (result.ValidationResult.IsValid) { Commit(); } return(result); }
public async Task <IActionResult> Add(Customer customer, CancellationToken cancellationToken) { if (ModelState.IsValid) { await customerService.AddAsync(customer, cancellationToken); return(Ok()); } return(BadRequest(customer)); }
public async Task <IActionResult> CreateCustomer([FromBody] CustomerCreateDto dto) { var response = await _userService.AddAsync(dto); if (response == null) { return(BadRequest(new { message = "Username is already taken." })); } return(Ok(response)); }
public async Task <IActionResult> AddAsync(CustomerAddDto customerCreateDto) { var result = await _customerService.AddAsync(customerCreateDto); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <IActionResult> Post(Customer customer) { var result = await _customerService.AddAsync(customer); if (result > 0) { return(CreatedAtAction(nameof(GetByCode), new { code = customer.CustomerCode }, await _customerService.GetByCodeAsync(customer.CustomerCode.ToString()))); } else { return(NoContent()); } }
public async Task <ActionResult> Create(CustomerModel customer) { try { var result = await _customerService.AddAsync(customer); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { var customer = new Customer { Id = user.Id, FirstName = Input.FirstName, LastName = Input.LastName, DateOfBirth = Input.DateOfBirth, Street = Input.Street, City = Input.City, Zipcode = Input.Zipcode, Country = Input.Country }; await _customerService.AddAsync(customer); _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <ActionResult <CustomerResponse> > AddCustomer(AddCustomerRequest customer) { try { var result = await _customerService.AddAsync(customer); return(Ok(result)); } catch (Exception ex) { _logger.LogError(ex, "Error in CustomersController->AddCustomer()"); return(StatusCode(StatusCodes.Status500InternalServerError, "There is some internal issue. Please try again later.")); } }
public async Task <IDataResult <User> > RegisterAsync(UserForRegisterDto userForRegisterDto) { var rulesResult = BusinessRules.Run((await this.UserExistAsync(userForRegisterDto.Email))); if (!rulesResult.Success) { return(new ErrorDataResult <User>(null, rulesResult.Message)); } HashingHelper.CreatePasswordHash(userForRegisterDto.Password, out byte[] passwordHash, out byte[] passwordSalt); var userToCreate = new User() { Email = userForRegisterDto.Email, FirstName = userForRegisterDto.FirstName, LastName = userForRegisterDto.LastName, PasswordHash = passwordHash, PasswordSalt = passwordSalt, Status = true }; var userAddResult = await _userService.AddAsync(userToCreate); if (!userAddResult.Success) { return(new ErrorDataResult <User>(null, Messages.UserNotAdded)); } var customerAddResult = await _customerService.AddAsync(new CustomerAddDto() { CompanyName = userForRegisterDto.CompanyName, UserId = userToCreate.Id }); if (!customerAddResult.Success) { return(new ErrorDataResult <User>(null, customerAddResult.Message)); } var authorizationResult = await AddDefaultAuthorizationAsync(userToCreate.Id); if (!authorizationResult.Success) { return(new ErrorDataResult <User>(null, authorizationResult.Message)); } return(new SuccessDataResult <User>(userToCreate, Messages.UserAdded)); }
protected IntegrationTestsBase() { //Arrange _server = new TestServer(new WebHostBuilder() .UseStartup <StartupTest>()); _client = _server.CreateClient(); _context = _server.Host.Services.GetService(typeof(SqlContext)) as SqlContext; IOrderRepository orderMockedRepository = _server.Host.Services.GetService(typeof(IOrderRepository)) as OrderMockedRepository; ICustomerRepository customerRepo = new CustomerRepository(_context); _customerService = new CustomerService(customerRepo, orderMockedRepository); _orderService = new OrderService(orderMockedRepository, customerRepo); _customerService.AddAsync(CustomerFixtures.GetCustomerList.FirstOrDefault()); }
public async Task <IActionResult> AddCustomerAsync([FromBody] CustomerModel customer) { try { if (customer == null) { return(NotFound()); } var result = await _customerService.AddAsync(_mapper.Map <CustomerDto>(customer)); return(Ok(result)); } catch (System.Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <ActionResult> Post([FromBody] CustomerDto customerDto) { try { if (customerDto == null) { return(BadRequest($"{nameof(customerDto)} can not not be null!")); } await _customerService.AddAsync(customerDto); return(Ok()); } catch (Exception e) { return(BadRequest(e)); } }
public async Task <IActionResult> Post([FromBody] Customer customer) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _repository.AddAsync(customer); return(Ok(customer)); } catch (Exception ex) { _loggerManager.LogError(ex.StackTrace + ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public override async Task HandleAsync(UserMessageInfo userMessageInfo, string argument) { const int maxLength = 30; if (argument.Length > maxLength) { await _messenger.SendMessageAsync(userMessageInfo, $"Название потребителя должно быть не больше {maxLength} символов", true); return; } await _customerService.AddAsync(new Customer { Caption = argument, GroupId = userMessageInfo.Group.Id }); await _messenger.SendMessageAsync(userMessageInfo, $"Добавлен новый потребитель: {argument}", true); }
// POST: api/Customer public async Task <HttpResponseMessage> Post(Customers customer) { try { //service.AddCustomer(customer); var result = await service.AddAsync(customer); if (result) { return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message.ToString())); } }
public async Task <ActionResult> PostAsync([FromBody] Customers item) { if (!ModelState.IsValid) { return(BadRequest()); } try { var exist = await service.GetAsync(x => x.email == item.email); if (exist != null) { return(Conflict(new Response() { Status = false, Description = "Duplicate record" })); } var result = await service.AddAsync(item); if (result) { var newitem = await service.GetAsync(x => x.email == item.email); return(StatusCode(201, newitem)); } else { return(BadRequest()); } } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(500, new Response() { Status = false, Description = "System error" })); } }
public async Task <ActionResult> Create(CustomerViewModel customerViewModel) { try { #region Validation if (!ModelState.IsValid) { return(View(customerViewModel)); } #endregion await _customerService.AddAsync(_mapper.Map <CustomerCoreModel>(customerViewModel)) .ConfigureAwait(false); return(RedirectToAction("Index")); } catch (Exception exception) { ViewBag.Error = exception.Message; return(View()); } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl ??= Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email, PhoneNumber = Input.PhoneNumber }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); await _signInManager.SignInAsync(user, isPersistent : false); await _customerService.AddAsync(new Customer { Address = Input.Address, FullName = Input.Email, UserId = user.Id, }); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public Task <IActionResult> AddAsync(CustomerModel model) { return(_customerService.AddAsync(model).ResultAsync()); }