You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IEditCustomersService.cs 1.4KB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Karsha_Site.Application.Interfaces.Contexts;
  2. using Karsha_Site.Common.Dto;
  3. using Microsoft.AspNetCore.Hosting;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.EntityFrameworkCore;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace Karsha_Site.Application.Services.Costomers.Commands.EditCustomers
  12. {
  13. public interface IEditCustomersService
  14. {
  15. ResultDto Execute(RequestEditCustomerDto request);
  16. }
  17. public class EditCustomersService: IEditCustomersService
  18. {
  19. private readonly IDataBaseContext _dataBaseContext;
  20. public EditCustomersService(IDataBaseContext context)
  21. {
  22. _dataBaseContext = context;
  23. }
  24. ResultDto IEditCustomersService.Execute(RequestEditCustomerDto request)
  25. {
  26. var customer = _dataBaseContext.Customers.Find(request.ID);
  27. if (customer == null)
  28. {
  29. return new ResultDto
  30. {
  31. IsSuccess = false,
  32. Message = "مشتری یافت نشد"
  33. };
  34. }
  35. customer.FullName = request.FullName;
  36. customer.Address = request.Address;
  37. customer.Link = request.Link;
  38. customer.UpdateTime = DateTime.Now;
  39. _dataBaseContext.SaveChanges();
  40. return new ResultDto()
  41. {
  42. IsSuccess = true,
  43. Message = "ویرایش مشتری انجام شد"
  44. };
  45. }
  46. }
  47. public class RequestEditCustomerDto
  48. {
  49. public int ID { get; set; }
  50. public string FullName { get; set; }
  51. public string Address { get; set; }
  52. public string Link { get; set; }
  53. }
  54. }