| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using Karsha_Site.Application.Interfaces.Contexts;
- using Karsha_Site.Application.Services.Costomers.Queries.GetCustomers;
- using Karsha_Site.Common.Dto;
- using Karsha_Site.Domain.Entinies.Customers;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- //using Microsoft.Extensions.Hosting;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace Karsha_Site.Application.Services.Costomers.Commands.InsetCustomers
- {
- public interface IInsertCustomersServise
- {
- ResultDto<ResultInsertCustomerDto> Execute(RequestInsertCustomerDto request);
- }
- public class InsertCustomersServise : IInsertCustomersServise
- {
-
- private readonly IHostingEnvironment _environment;
- private readonly IDataBaseContext _dataBaseContext;
- public InsertCustomersServise(IDataBaseContext context, IHostingEnvironment hostingEnvironment)
- {
- _dataBaseContext = context;
- _environment = hostingEnvironment;
- }
- public ResultDto<ResultInsertCustomerDto> Execute(RequestInsertCustomerDto request)
- {
- Customer customer = new Customer()
- {
- Address = request.Address,
- FullName = request.FullName,
- //Image = request.Image.FileName,
- Link = request.Link,
- };
- Karsha_Site.Common.UploadFiles uploads = new Karsha_Site.Common.UploadFiles(_environment);
- var uploadedResult = uploads.UploadFile(request.Image, $@"images\CustomerImages\");
- if (uploadedResult != null)
- {
- customer.Image = uploadedResult.FileNameAddress;
- }
- customer.Code = _dataBaseContext.Customers.Count() + 1;
- customer.InsertTime = DateTime.Now;
-
- _dataBaseContext.Customers.Add(customer);
- _dataBaseContext.SaveChanges();
-
- return new ResultDto<ResultInsertCustomerDto>(){
- Data = new ResultInsertCustomerDto()
- {
- CustomerId = customer.ID
- },
- IsSuccess = true,
- Message = "مشتری با موفقیت ثبت شد"
- };
- }
-
-
- }
-
- public class RequestInsertCustomerDto
- {
- public string FullName { get; set; }
- public string Address { get; set; }
- public string Link { get; set; }
- public IFormFile Image { get; set; }
- }
- public class ResultInsertCustomerDto
- {
- public int CustomerId { get; set; }
- }
- }
|