using Karsha_Site.Application.Interfaces.Contexts; using Karsha_Site.Common.Dto; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Karsha_Site.Application.Services.Costomers.Commands.EditCustomers { public interface IEditCustomersService { ResultDto Execute(RequestEditCustomerDto request); } public class EditCustomersService: IEditCustomersService { private readonly IDataBaseContext _dataBaseContext; public EditCustomersService(IDataBaseContext context) { _dataBaseContext = context; } ResultDto IEditCustomersService.Execute(RequestEditCustomerDto request) { var customer = _dataBaseContext.Customers.Find(request.ID); if (customer == null) { return new ResultDto { IsSuccess = false, Message = "مشتری یافت نشد" }; } customer.FullName = request.FullName; customer.Address = request.Address; customer.Link = request.Link; customer.UpdateTime = DateTime.Now; _dataBaseContext.SaveChanges(); return new ResultDto() { IsSuccess = true, Message = "ویرایش مشتری انجام شد" }; } } public class RequestEditCustomerDto { public int ID { get; set; } public string FullName { get; set; } public string Address { get; set; } public string Link { get; set; } } }