public async Task <IActionResult> CreateSupplier(CreateSupplierDto createSupplierDto) { if (createSupplierDto != null) { try { var supplier = new Supplier { Address = createSupplierDto.Address, Phone = createSupplierDto.Phone, SupplierName = createSupplierDto.SupplierName }; var isCreated = await _supplierService.CreateSupplier(supplier); if (isCreated) { return(Ok(supplier)); } } catch (Exception e) { Trace.WriteLine(e.Message); } } return(BadRequest()); }
public async Task <GetSupplierDto> CreateSupplierAsync(CreateSupplierDto supplierDto) { await CheckSupplierAsync(0, supplierDto.Name); var supplier = _mapper.Map <Supplier>(supplierDto); supplier = await _supplier.AddSupplierAsync(supplier); return(_mapper.Map <GetSupplierDto>(supplier)); }
public async Task <Response <SupplierDto> > Update(Guid id, CreateSupplierDto entityDto) { Supplier supplier = await _context.Suppliers.FindAsync(id); if (supplier == null) { throw new RestException(HttpStatusCode.NotFound, new { Supplier = "Not found" }); } supplier.Address = entityDto.Address; supplier.Email = entityDto.Email; supplier.Name = entityDto.Name; supplier.Phone = entityDto.Phone; supplier.ShopName = entityDto.ShopName; supplier.UpdatedAt = DateTime.Now; if (entityDto.Photo != null) { if (supplier.Photo != null) { _photoAccessor.Delete(supplier.Photo); } string path = _photoAccessor.Add("suppliers", entityDto.Photo); supplier.Photo = path; } var success = await _context.SaveChangesAsync() > 0; if (success) { var supplierDto = _mapper.Map <Supplier, SupplierDto>(supplier); return(new Response <SupplierDto> { Data = supplierDto, Message = $"Supplier {supplierDto.Name} updated", Time = DateTime.Now, IsSuccess = true }); } ; throw new Exception("Problem on saving category"); }
public CreateSupplierDtoValidatorFixture() { Validator = new CreateSupplierDtoValidator(); Model = new CreateSupplierDto { Name = "Test Supplier Pvt Ltd", Address1 = "#03-81, BLK 227", Address2 = "Bishan Street 23", City = "Bishan", Country = "Singapore", Telephone1 = "+94666553456", Telephone2 = "+94888775678", Fax = "+94666448856", Email = "*****@*****.**", ContactPerson = "James" }; }
public async Task <Response <SupplierDto> > Create(CreateSupplierDto createEntityDto) { try { Supplier supplier = new Supplier { Name = createEntityDto.Name, Phone = createEntityDto.Phone, Email = createEntityDto.Email, Address = createEntityDto.Address, ShopName = createEntityDto.ShopName, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; if (createEntityDto.Photo != null) { string path = _photoAccessor.Add("suppliers", createEntityDto.Photo); supplier.Photo = path; } await _context.Suppliers.AddAsync(supplier); await _context.SaveChangesAsync(); var returnEntityDto = _mapper.Map <Supplier, SupplierDto>(supplier); return(new Response <SupplierDto> { Data = returnEntityDto, Message = "Supplier saved", Time = DateTime.Now, IsSuccess = true }); } catch (Exception e) { return(new Response <SupplierDto> { Data = null, Message = e.Message, Time = DateTime.Now, IsSuccess = false }); } }
public SupplierRepositoryFixture() { MockSupplierService = new Mock <ISupplierService>(); Suppliers = new List <Supplier> { new Supplier { Id = 1, Name = "ABC Pvt Ltd", Address1 = "American Mission School Road", Address2 = "Madduvil South", City = "Chavakachcheri", Country = "Sri Lanka", Telephone1 = "0765554345", Telephone2 = "0766554567", Fax = "", Email = "*****@*****.**", ContactPerson = "James" }, new Supplier { Id = 2, Name = "VBT Pvt Ltd", Address1 = "VBT Road", Address2 = "VBTt", City = "Jaffna", Country = "Sri Lanka", Telephone1 = "0777113644", Telephone2 = "", Fax = "", Email = "*****@*****.**", ContactPerson = "James" } }; CollectionEnvelop = new CollectionEnvelop <Supplier> { Items = Suppliers, ItemsPerPage = 10, TotalItems = 2, }; CreateSupplierDto = new CreateSupplierDto { Name = "Jaffna Supplier Pvt Ltd", Address1 = "Kandy Road", Address2 = "Kaithady", City = "Jaffna", Country = "Sri Lanka", Telephone1 = "+94666553456", Telephone2 = "+94888775678", Fax = "+94666448856", Email = "*****@*****.**", ContactPerson = "Aathavan" }; CreatedNewSupplier = new Supplier { Id = 3, Name = CreateSupplierDto.Name, Address1 = CreateSupplierDto.Address1, Address2 = CreateSupplierDto.Address2, City = CreateSupplierDto.City, Country = CreateSupplierDto.Country, Telephone1 = CreateSupplierDto.Telephone1, Telephone2 = CreateSupplierDto.Telephone2, Fax = CreateSupplierDto.Fax, Email = CreateSupplierDto.Email, ContactPerson = CreateSupplierDto.ContactPerson }; EditSupplierDto = new EditSupplierDto { Name = "VBT Pvt Ltd", Address1 = "#03-46, Blk 687", Address2 = "Hindu College Road", City = "Jaffna", Country = "Sri Lanka", Telephone1 = "0777113644", Telephone2 = "0777113644", Fax = "0777113644", Email = "*****@*****.**", ContactPerson = "James" }; }
public async Task <IActionResult> CreateSupplier(CreateSupplierDto supplierDto, ApiVersion version) { var result = await _repository.CreateSupplierAsync(supplierDto); return(CreatedAtRoute(new { id = result.Id, version = $"{version}" }, result)); }
public SupplierControllerFixture() { ApiVersion = new ApiVersion(1, 0); MockSupplierRepository = new Mock <ISupplierRepository>(); Suppliers = new List <GetSupplierDto> { new GetSupplierDto { Id = 1, Name = "Test Supplier Pvt Ltd", Address1 = "#03-81, BLK 227", Address2 = "Bishan Street 23", City = "Bishan", Country = "Singapore", Telephone1 = "+94666553456", Telephone2 = "+94888775678", Fax = "+94666448856", Email = "*****@*****.**", ContactPerson = "James" }, }; SupplierEnvelop = new SupplierEnvelop { SupplierCount = 1, Suppliers = Suppliers, ItemsPerPage = 10, TotalPages = 1 }; ValidCreateSupplierDto = new CreateSupplierDto { Name = "Jaffna Supplier Pvt Ltd", Address1 = "Kandy Road", Address2 = "Kaithady", City = "Jaffna", Country = "Sri Lanka", Telephone1 = "+94666553456", Telephone2 = "+94888775678", Fax = "+94666448856", Email = "*****@*****.**", ContactPerson = "Aathavan" }; CreateSupplierDtoResult = new GetSupplierDto { Id = 2, Name = "Jaffna Supplier Pvt Ltd", Address1 = "Kandy Road", Address2 = "Kaithady", City = "Jaffna", Country = "Sri Lanka", Telephone1 = "+94666553456", Telephone2 = "+94888775678", Fax = "+94666448856", Email = "*****@*****.**", ContactPerson = "Aathavan" }; ValidEditSupplierDto = new EditSupplierDto { Name = "Colombo Supplier Pvt Ltd", Address1 = "#06-02, Perea Lane", Address2 = "Wellawatta", City = "Colombo", Country = "Sri Lanka" }; EditSupplierDtoResult = new GetSupplierDto { Id = 1, Name = "Colombo Supplier Pvt Ltd", Address1 = "#06-02, Perea Lane", Address2 = "Wellawatta", City = "Colombo", Country = "Sri Lanka", Telephone1 = "+94666553456", Telephone2 = "+94888775678", Fax = "+94666448856", Email = "*****@*****.**", ContactPerson = "James" }; }
public ActionResult Edit(Guid id, [FromForm] CreateSupplierDto supplierDto) { var result = _repo.Update(id, supplierDto); return(Ok(result)); }
public ActionResult Create([FromForm] CreateSupplierDto supplierDto) { var result = _repo.Create(supplierDto); return(Ok(result)); }