public IActionResult Add(Customer customer) { var result = _customerService.Add(customer); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public ActionResult Create(CustomerViewModel customer) { if (ModelState.IsValid) { _service.Add(customer.MapTo <Customer>()); return(RedirectToAction("Index")); } return(View(customer)); }
public IActionResult Create([FromBody] CustomerViewModel customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var id = _customerService.Add(customer); return(Created($"api/Customer/{id}", id)); }
public IActionResult AddCustomer(Customer Customer) { var data = _customerService.Add(Customer); if (data.Success) { return(Ok(data)); } return(BadRequest(data.Message)); }
public IActionResult Add(Customer entity) { var result = _entityService.Add(entity); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public ActionResult <CustomerViewModel> PostCustomer([FromBody] CustomerViewModel customer) { if (customer == null || string.IsNullOrWhiteSpace(customer.Name)) { //teste return(NoContent()); } return(Created(nameof(GetByName), _customerService.Add(customer))); }
public ActionResult Post([FromBody] Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Adds new customer _customerService.Add(customer); return(CreatedAtAction("Get", new { id = customer.Id }, customer)); }
public IResult Add(Customer customer) { if (customer.UserId != 0) { _customerDal.Add(customer); return(new SuccessResult(Messages.CustomerAdded)); } return(new ErrorResult(Messages.CustomerNotAdded)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapGet("/api/customers", async context => { await context.Response.WriteAsync("Hello Customers!"); }); endpoints.MapGet("/api/customers/{id:int}", async context => { string id = context.Request.RouteValues["id"].ToString(); int customerId = int.Parse(id); ICustomerService customerService = context.RequestServices.GetRequiredService <ICustomerService>(); var customer = customerService.Get(customerId); string json = JsonConvert.SerializeObject(customer); context.Response.Headers.Append("Content-Type", "application/json"); await context.Response.WriteAsync(json); }); endpoints.MapPost("/api/customers", async context => { StreamReader streamReader = new StreamReader(context.Request.Body); string json = await streamReader.ReadToEndAsync(); Customer customer = JsonConvert.DeserializeObject <Customer>(json); ICustomerService customerService = context.RequestServices.GetRequiredService <ICustomerService>(); customerService.Add(customer); context.Response.StatusCode = StatusCodes.Status201Created; await context.Response.WriteAsync("Created"); }); endpoints.MapGet("/api/reports", async context => { await context.Response.WriteAsync("Hello Reports!"); }); endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); }); }); }
public IActionResult Add([FromBody] Customer customer) { var result = customerService.Add(customer); if (result.IsSuccess) { return(Ok(result)); } return(BadRequest(result.Message)); }
public IActionResult Add([FromBody] Customer customer) { try { return(Ok(_service.Add(customer))); } catch (Exception ex) { return(BadRequest(ex)); } }
public ActionResult Create([Bind(Include = "FullName, CompanyName, Phone, Email, Fax")] CustomerVM customerVM) { if (ModelState.IsValid) { CustomerDTO customerDTO = Mapper.Map <CustomerDTO>(customerVM); _customerService.Add(customerDTO); return(RedirectToAction("Index")); } return(View()); }
public IActionResult Add(Customer customer) // Post olduğu için, ne istediğimizi buraya yazıyoruz. { var result = _customerService.Add(customer); if (result.Success == true) { return(Ok(result)); } return(BadRequest()); }
// Post: Admin/Customer/Add/id public virtual ActionResult Add(CustomerAdd model) { if (!ModelState.IsValid) { return(View(model)); } _customerService.Add(model); _uow.SaveAllChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult <CustomerViewModel> > AddCustomer(CustomerViewModel customerViewModel) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } await _customerService.Add(_mapper.Map <Customer>(customerViewModel)); return(CustomResponse(customerViewModel)); }
public IActionResult Add([FromBody] CustomerViewModel customerViewModel) { try { // Mapping Done Customer customer = new Customer(); customer = ObjectMapper <CustomerViewModel, Customer> .Map(customerViewModel); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Guid id = Guid.NewGuid(); customer.CustomerGuid = id; customer.CreatedOn = DateTime.Now; customer.CreatedBy = id; customer.UpdatedOn = DateTime.Now; customer.UpdatedBy = id; customer.IsActive = true; customer.IsDeleted = false; var CustomerName = customer.CustomerName; if (string.IsNullOrEmpty(customer.CustomerCode)) { customer.CustomerCode = "N/A"; } else { if (_customerService.CheckDuplicates(customer) > 0) { ModelState.AddModelError("", "Duplicate value entered for either code or name !!"); return(BadRequest(ModelState)); } } _customerService.Add(customer); //audit log.. var additionalInformation = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Added.ToString(), ResourceType.Customer.ToString()); var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + "/admin/Customer"; var additionalInformationWithUri = string.Format("<a href=\"{0}\">{1}</a>", additionalInformationURl, additionalInformation); var resource = string.Format("{0} </br> GUID: {1} </br> Customer Name: {2} </br> Customer Code: {3}", ResourceType.Customer.ToString(), customer.CustomerGuid, customer.CustomerName, customer.CustomerCode); AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), customer, resource, customer.CustomerGuid, UserHelper.GetHostedIp(HttpContext), "Customer Added", Guid.Empty, "Successful", "", additionalInformationWithUri, additionalInformationURl); return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Added !!", customer = new { customerGuid = customer.CustomerGuid, customerName = customer.CustomerName } })); } catch (ArgumentException ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult EditCustomer(EditCustomerViewModel model) { if (!ModelState.IsValid) { TempData["ErrorBannerMessage"] = "Customer was not saved. Check to make sure your info was not too long (typically 50 characters or less)."; } if (model.Customer.Id == 0) { model.Customer.Id = _customerService.Add(model.Customer); TempData["SuccessBannerMessage"] = "Customer successfully added."; } else { _customerService.Edit(model.Customer); TempData["SuccessBannerMessage"] = "Customer successfully updated."; } return(RedirectToAction("Index")); }
public Customer Add(Customer customer) { var result = _validator.Validate(customer); if (!result.IsValid) { throw new InvalidOperationException(result.ToString()); } return(_customerService.Add(customer)); }
public ActionResult Create([FromBody] Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _customerService.Add(customer); return(Ok(result)); }
public IActionResult Add(CustomerDto customerDto) { var customerDtoNew = _customerService.Add(customerDto); var customerJson = Newtonsoft.Json.JsonConvert.SerializeObject(customerDtoNew); TempData["customerJson"] = customerJson; return(RedirectToAction("DisplayCustomerCode")); }
public async Task <IActionResult> Add(Customer customer) { var result = await _customerService.Add(customer); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public ActionResult Create([Bind(Include = "Id,CustomerCode,Name,Address,Phone")] CustomerEditDTO customer) { CustomerDTO newCustomer = new CustomerDTO(); if (ModelState.IsValid) { newCustomer = _customerService.Add(customer); return(RedirectToAction("Index")); } return(View(newCustomer)); }
public JavaScriptResult Create(CustomerViewModel customervm) { try { _customerService.Add(Mapper.Map <Customer>(customervm)); return(JavaScript($"ShowResult('{"Data saved successfully."}','{"success"}','{"redirect"}','{"/Customer/?companyId=" + customervm.CompanyId + "&&branchId=" + customervm.BranchId}')")); } catch (Exception ex) { return(JavaScript($"ShowResult('{ex.Message}','failure')")); } }
public async Task <ActionResult> Add(Customer customer) { if (!ModelState.IsValid) { var value = ModelState.Values.GetParams(); return(RedirectToAction("Add", new { errors = value })); } await _customerService.Add(customer); return(RedirectToAction("Index")); }
public async Task <ActionResult <Guid> > Save([FromBody] SaveCustomerRequest request) { var validator = new SaveCustomerValidator(); var validationResult = await validator.ValidateAsync(request); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } return(Created("", await _customerService.Add(request))); }
public IActionResult Post([FromBody] Customer customer, [FromServices] IMessageService messageService) { customerService.Add(customer); // TODO: // Send email // Send sms messageService.Send($"Dziękujemy {customer.FirstName} {customer.LastName}"); return(CreatedAtRoute(nameof(GetById), new { Id = customer.Id }, customer)); }
public async Task <IActionResult> Post(Customer customer) { customerService.Add(customer); await hubContext.Clients.All.SendAsync("Added", customer); await hubContext.Clients.Group("Altkom").SendAsync("Added", customer); // hubContext.AddedCustomer(customer); return(CreatedAtRoute(new { id = customer.Id }, customer)); }
public IHttpActionResult Add(CustomerViewModel viewModel) { try { var model = _customerService.Add(viewModel); return(Ok(new { message = "Record has been successfully added.", customerAdded = model })); } catch (Exception ex) { return(Ok(new { message = ex.Message })); } }
public IActionResult AddOrUpdateCustomer(CustomerViewModel model) { if (model.Customer.Id == 0) { _customerService.Add(model.Customer); } else { _customerService.Update(model.Customer); } return(RedirectToAction("Customer", "Customer", new { Id = model.Customer.Id })); }
public async Task <IActionResult> Post([FromBody] Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _customerService.Add(customer); await _unitOfWork.SaveChangesAsync(); return(Ok(customer)); }