public string Post([FromForm] ProductsDto product) { try { if (product.files.Length > 0) { string path = _environment.WebRootPath + "\\images\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (FileStream fileStream = System.IO.File.Create(path + product.files.FileName)) { product.files.CopyTo(fileStream); return("uploaded"); } } else { return("Not Uploaded"); } } catch (Exception ex) { return("File is empty"); } }
public ProductsResponseDto Get(ProductsDto request) { var pageSize = 5; var page = request.Page; if(page < 0) page = 0; var productsList = Repository.PagedProducts(page, pageSize); var productsResponseDtoList = productsList.ConvertAll(a => a.TranslateTo<ProductResponseDto>()); //var products = Db.Select<Product> // (a => // a.OrderByDescending(b => b.Id) // .Limit(pageSize * request.Page, pageSize) // ) // .ConvertAll(a => a.TranslateTo<ProductResponseDto>()); var response = new ProductsResponseDto { Products = productsResponseDtoList, Page = page, PageSize = pageSize }; return response; }
public async Task SubmitAsync(string createBy, IEnumerable <OrderDetailsDto> orderDetails) { var orderDto = new OrderDto { CreatedAt = DateTime.Now, CreatedBy = createBy, Sku = Guid.NewGuid().ToString("n").Substring(0, 6) }; var config = new MapperConfiguration(cfg => cfg.CreateMap <OrderDto, Order>()); var mapper = config.CreateMapper(); var orderEntity = mapper.Map <Order>(orderDto); //_unitOfWork.OrderRepository.Add(orderEntity); var productDto = new ProductsDto { Create = DateTime.Now, }; var config2 = new MapperConfiguration(cfg => cfg.CreateMap <ProductsDto, Product>()); var mapper2 = config2.CreateMapper(); var productEntity = mapper2.Map <Product>(productDto); foreach (var details in orderDetails) { details.Order = orderEntity; details.CreateAt = DateTime.Now; details.Product = productEntity; _unitOfWork.OrderDetailsRepository.Add(DtoToEntity(details)); } await _unitOfWork.SaveAsync(); }
private void btnUpdate_Click(object sender, EventArgs e) { var id = _dto.Id; var name = this.tbProductName.Text; var supplierId = (int)this.cbSupplier.SelectedValue; var productDto = new ProductsDto { Id = id, Name = name, SupplierId = supplierId }; var op = new updateProductOperation(productDto); var result = OperationManager.Instance.ExecuteOperation(op); if (result.IsSuccessful) { MessageBox.Show("Successfuly updated!"); } else { MessageBox.Show(result.Errors.First()); } }
public async Task <ActionResult> UpdateProduct(int id, ProductsDto body) { await _DataProducts.UpdateProduct(id, body); // Retorna un 204 return(NoContent()); }
/// <summary> /// Edit department /// </summary> /// <param name="dto"></param> /// <returns></returns> public IActionResult Edit(ProductsDto dto) { if (!ModelState.IsValid) { return(Json(new { Result = "Faild", Message = GetModelStateError() })); } try { if (dto.Id == Guid.Empty) { dto.Id = Guid.NewGuid(); dto.CreatedTime = DateTime.Now; dto.ModifiedTime = DateTime.Now; } else if (dto.Id != Guid.Empty) { dto.ModifiedTime = DateTime.Now; } if (_proAppservice.InsertOrUpdate(dto)) { return(Json(new { Result = "Success" })); } return(Json(new { Result = "Faild" })); } catch (Exception ex) { return(Json(new { Result = "Faild", Message = ex.Message })); } }
public ProductsResponseDto Get(ProductsDto request) { var pageSize = 5; var page = request.Page; if (page < 0) { page = 0; } var productsList = Repository.PagedProducts(page, pageSize); var productsResponseDtoList = productsList.ConvertAll(a => a.TranslateTo <ProductResponseDto>()); //var products = Db.Select<Product> // (a => // a.OrderByDescending(b => b.Id) // .Limit(pageSize * request.Page, pageSize) // ) // .ConvertAll(a => a.TranslateTo<ProductResponseDto>()); var response = new ProductsResponseDto { Products = productsResponseDtoList, Page = page, PageSize = pageSize }; return(response); }
// [HttpGet("{id}")] public IActionResult GetProductByCategory(int id) { var products = _dataService.GetProductByCategory(id); if (products.Count == 0) { return(NotFound(products)); } // Passing data through DTO List <ProductsDto> newProducts = new List <ProductsDto>(); foreach (var item in products) { var dto = new ProductsDto() { Id = item.Id, Name = item.Name, CategoryId = item.CategoryId, CategoryName = item.Category.Name }; newProducts.Add(dto); } return(Ok(newProducts)); }
public async Task <ActionResult> CustomerProductsCreate(UsersDto customer, ProductsDto product) { var customerResult = await _customersRepository.GetAsync(customer.Id); TempData["customer"] = customerResult.Data; var productResult = await _productsRepository.GetAllAsync(); ViewBag.Products = productResult.Data; var customerProducts = await _customersProductsRepository.GetAllByCustomerIdAsync(customer.Id); var customerAlreadyHasProduct = customerProducts.Data.Exists(e => e.ProductsId == product.Id); if (customerAlreadyHasProduct) { var modelResult = new TaskResult <CustomersProductsDto> { Message = "El cliente ya tiene este producto", Success = false }; return(View("CustomerProductsCreate", modelResult)); } var customerProduct = new CustomersProductsDto { ProductsId = product.Id, ApplicationUserId = customer.Id }; var relResult = await _customersProductsRepository.SaveAsync(customerProduct); return(View("CustomerProductsCreate", relResult)); }
public IHttpActionResult Get(string name = "") { ProductsDto productResult = new ProductsDto(); if (string.IsNullOrWhiteSpace(name)) { var products = _productRepository.GetAll(); productResult.Items = Mapper.Map <List <ProductDto> >(products); } else { var products = _productRepository.GetProducts(name); if (products == null) { return(NotFound()); } productResult.Items = Mapper.Map <List <ProductDto> >(products); } if (productResult == null) { return(NotFound()); } return(Ok(productResult)); }
public async Task <IActionResult> GetProducts([FromQuery] string name) { List <Product> products = null; if (name == null) { products = await repository.GetAllProducts(); } else { products = await repository.FindProductsByName(name); } if (products == null) { logger.LogInformation($"Product with Name {name} not found."); return(NotFound()); } var productDtos = Mapper.Map <IEnumerable <ProductDto> >(products); var result = new ProductsDto() { Items = productDtos.ToList() }; return(Ok(result)); }
public ActionResult Index(ProductsDto productsRequest) { //var logger = LogManager.GetLogger(GetType()); //logger.Debug("test here"); var products = ProductsService.Get(productsRequest); return View(products); }
public static void CopyFromEntity(AllOrderDetails response, Order order) { response.agentadmin_mobile = order.AgentAdmin != null ? order.AgentAdmin.MobileNumber : string.Empty; response.agentadmin_image = order.AgentAdmin != null ? ImagePathService.agentAdminImagePath + order.AgentAdmin.ProfileImage : string.Empty; response.agentadmin_name = order.AgentAdmin != null ? order.AgentAdmin.AgentAdminName : string.Empty; response.delivery_date = Common.ToDateFormat(order.DeliveryDate); response.delivery_status = order.OrderDeliveries.Count > 0 ? order.OrderDeliveries.Where(x => x.OrdrID == order.OrdrID).FirstOrDefault().StatusId : 0; response.grand_total = order.GrandTotal; response.invoice_number = order.InvoiceNumber; response.order_date = Common.ToDateFormat(order.OrderDate); response.order_id = order.OrdrID; response.order_status = order.StatusID; response.order_time = order.OrderTime.ToString(); response.time_slot_name = order.MDeliverySlot != null ? order.MDeliverySlot.SlotName : string.Empty; if (response.driver_details == null) { response.driver_details = new DriverDetailsDto(); } if (order.Driver != null) { response.driver_details.driver_id = order.Driver.DrvrID; response.driver_details.driver_name = order.Driver.DriverName; response.driver_details.driver_image = ImagePathService.driverImagePath + order.Driver.ProfileImage; response.driver_details.driver_mobile = order.Driver.MobileNumber; } else { response.driver_details.driver_name = string.Empty; response.driver_details.driver_image = string.Empty; response.driver_details.driver_mobile = string.Empty; } if (response.product_details == null) { response.product_details = new List <ProductsDto>(); } foreach (var item in order.OrderDetails) { ProductsDto prodDto = new ProductsDto(); OrdersHelper.CopyFromEntity(prodDto, item); response.product_details.Add(prodDto); } response.has_exchange = (order.OrderPrdocuctExchanges.Count > 0 ? 1 : 0); if (response.has_exchange == 1) { if (response.exchange == null) { response.exchange = new List <ExchangeDto>(); } foreach (var item in order.OrderPrdocuctExchanges) { ExchangeDto exDto = new ExchangeDto(); OrdersHelper.CopyFromEntity(exDto, item); response.exchange.Add(exDto); } } }
public async Task Update(ProductsDto model) { var basketContent = new StringContent(JsonConvert.SerializeObject(model), System.Text.Encoding.UTF8, "application/json"); var response = await _apiClient.PostAsync("", basketContent); _kitchenSender.SendCustomer(model); response.EnsureSuccessStatusCode(); }
public ActionResult Index(ProductsDto productsRequest) { //var logger = LogManager.GetLogger(GetType()); //logger.Debug("test here"); var products = ProductsService.Get(productsRequest); return(View(products)); }
public async Task UpdateProduct(int id, ProductsDto body) { var entry = await _context.Products.SingleAsync(x => x.IdProduct == id); entry.Name = body.Name; entry.Price = body.Price; entry.Description = body.Description; await _context.SaveChangesAsync(); }
public TaskResult <List <CustomersProductsDto> > GetAll() { List <CustomersProductsDto> costumersDtos = new List <CustomersProductsDto>(); var result = new TaskResult <List <CustomersProductsDto> >(); try { var customers = _context.CustomersProducts .Include(e => e.Product) .Where(e => e.Active).ToList(); foreach (var customer in customers) { var customerInfo = _customersRepository.Get(customer.ApplicationUserId); var customerDto = new UsersDto { Active = customerInfo.Data.Active, CreatedAt = customerInfo.Data.CreatedAt, Email = customerInfo.Data.Email, Id = customerInfo.Data.Id, LastName = customerInfo.Data.LastName, Name = customerInfo.Data.Name, UpdatedAt = customerInfo.Data.UpdatedAt, DocumentNumber = customerInfo.Data.DocumentNumber, PhoneNumber = customerInfo.Data.PhoneNumber }; var productsDto = new ProductsDto { Active = customer.Product.Active, CreatedAt = customer.Product.CreatedAt, Id = customer.Product.Id, Name = customer.Product.Name, Description = customer.Product.Description, Price = customer.Product.Price }; costumersDtos.Add( new CustomersProductsDto { Active = customer.Active, CreatedAt = customer.CreatedAt, Id = customer.Id, ProductsId = customer.ProductsId, ApplicationUserId = customer.ApplicationUserId, Product = productsDto }); } result.Data = costumersDtos; } catch (Exception e) { result.Success = false; result.Message = $"Error al recuperar el listado de clientes: {e.Message}"; } return(result); }
public HttpResponseMessage AddProduct(ProductsDto product) { var repo = new ProductsRepository(); var result = repo.Create(product); if (result) { return(Request.CreateResponse(HttpStatusCode.Created)); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Could not create product, try again later...")); }
public HttpResponseMessage UpdateProduct(int ProductId, ProductsDto product) { var repository = new ProductsRepository(); var result = repository.UpdateProductStatus(product.OutOfStock, ProductId); if (result) { return(Request.CreateResponse(HttpStatusCode.Created)); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Could not update product")); }
public async Task <ActionResult> Create(ProductsDto Data) { if (!ModelState.IsValid) { return(View()); } var newModel = await _productsRepository.SaveAsync(Data); return(View(newModel)); }
public async Task <ActionResult> CreateProduct(ProductsDto body) { var result = await _DataProducts.CreateProduct(body); // Retorna un 201 return(CreatedAtAction( "GetProductById", new { id = result.IdProduct }, result )); }
public async Task <IHttpActionResult> GetAll() { var products = await _productRepository.ListAsync(); var productsDto = new ProductsDto { Items = Mapper.Map <IEnumerable <ProductDto> >(products) }; return(Ok(productsDto)); }
public async Task <IHttpActionResult> SearchByName(string name) { var products = await _productRepository.GetByNameAsync(name); var productsDto = new ProductsDto { Items = Mapper.Map <IEnumerable <ProductDto> >(products) }; return(Ok(productsDto)); }
public static void CopyFromEntity(OrderDetailsDto dto, Order order, string agentAdminMob, bool withDetails) { dto.order_id = order.OrdrID; dto.invoice_number = order.InvoiceNumber; // driver_details : driver_name, driver_image dto.order_date = Common.ToDateFormat(order.OrderDate); // product_details : product_name, quantity, unit_price, sub_total, product_promo, shipping_cost, shipping_promo dto.order_time = order.OrderTime; dto.delivery_date = Common.ToDateFormat(order.DeliveryDate); dto.time_slot_name = order.MDeliverySlot.SlotName; dto.grand_total = order.GrandTotal; dto.order_status = order.MOrderStatu.OrderStatus; dto.agentadmin_mobile = agentAdminMob; OrderDelivery odel = order.OrderDeliveries.Count > 0 ? order.OrderDeliveries.First() : null; if (odel != null) { dto.delivery_status = odel.MDeliveryStatu.DeliveryStatus; if (odel.Driver != null) { DriverDetailsDto drvDto = new DriverDetailsDto(); dto.driver_details = drvDto; CopyFromEntity(drvDto, odel.Driver); //drvDto.driver_name = odel.Driver.DriverName; //drvDto.driver_image = odel.Driver.ProfileImage; } } if (order.OrderDetails.Count > 0) { List <OrderDetail> odetLst = order.OrderDetails.ToList(); dto.product_details = new ProductsDto[odetLst.Count]; for (int i = 0; i < odetLst.Count; i++) { ProductsDto prodDto = new ProductsDto(); CopyFromEntity(prodDto, odetLst[i]); dto.product_details[i] = prodDto; } } dto.has_exchange = (order.OrderPrdocuctExchanges.Count > 0 ? 1 : 0); if (dto.has_exchange == 1) { if (dto.exchange == null) { dto.exchange = new List <ExchangeDto>(); } foreach (var item in order.OrderPrdocuctExchanges) { ExchangeDto exDto = new ExchangeDto(); CopyFromEntity(exDto, item); dto.exchange.Add(exDto); } } }
public async Task <ActionResult> Edit(ProductsDto Data) { if (!ModelState.IsValid) { return(View(new TaskResult <ProductsDto> { Data = Data })); } var model = await _productsRepository.UpdateAsync(Data); return(View(model)); }
public void Put(int id, [FromBody] ProductsDto productsDto) { var product = _bikeStoresRepository.ProductGetById(id); if (product.ProductId > 0) { return; } _mapper.Map(productsDto, product); _bikeStoresRepository.UpdateProduct(product); _bikeStoresRepository.SaveData(); }
public ActionResult GetProducts() { List <ProductDto> products = _productService.GetProducts(UserId); var result = new ProductsDto() { Products = products, Names = _consumptionService.GetConsumptionNames(UserId) .Where(x => !products.Any(y => y.Name == x)) .ToList() }; return(Ok(result)); }
public UpdateForm(ProductsDto dto) { _dto = dto; InitializeComponent(); this.tbProductName.Text = _dto.Name; var op = new getSuppliersOperation(); var supDto = OperationManager.Instance.ExecuteOperation(op).Data as IEnumerable <SupplierDto>; PopulateComboBoxes(this.cbSupplier, supDto); this.cbSupplier.SelectedValue = _dto.SupplierId; }
public static void CopyFromEntity(ProductsDto dto, OrderDetail odet) { dto.product_id = odet.ProdID; dto.product_name = odet.Product != null ? odet.Product.ProductName : string.Empty; dto.product_promo = odet.PromoProduct; dto.quantity = odet.Quantity; dto.shipping_cost = odet.ShippingCharge; dto.shipping_promo = odet.PromoShipping; dto.sub_total = odet.SubTotal; dto.unit_price = odet.UnitPrice; dto.refill_price = odet.RefillPrice; dto.refill_promo = odet.PromoRefill; dto.refill_quantity = odet.RefillQuantity; }
public async Task <ProductsDto> CreateProduct(ProductsDto body) { var entry = new Products { Name = body.Name, Price = body.Price, Description = body.Description }; await _context.AddAsync(entry); await _context.SaveChangesAsync(); return(_mapper.Map <ProductsDto>(entry)); }
public void Store(ProductsDto dto) { var category = _categoryRepository.GetById(dto.Category.Id); var product = _productRepository.GetById(dto.Id); if (product == null) { product = new Product(dto.Name, category, dto.Price, dto.StockQuantity); _productRepository.Save(product); } else { product.Update(dto.Name, category, dto.Price, dto.StockQuantity); } }
public async Task <TaskResult <List <ComplaintsOptionsDto> > > GetAllAsync() { List <ComplaintsOptionsDto> complaintsOptions = new List <ComplaintsOptionsDto>(); var result = new TaskResult <List <ComplaintsOptionsDto> >(); try { var complaintsOps = await _context .ComplaintsOptions .Include(e => e.Product) .Include(e => e.Department) .Where(e => e.Deleted == false).ToListAsync(); complaintsOps.ForEach((option) => { var productDto = new ProductsDto { Active = option.Product.Active, CreatedAt = option.Product.CreatedAt, Id = option.Product.Id, Name = option.Product.Name, UpdatedAt = option.Product.UpdatedAt, Description = option.Product.Description, Price = option.Product.Price }; complaintsOptions.Add(new ComplaintsOptionsDto { Active = option.Active, CreatedAt = option.CreatedAt, Id = option.Id, ProductsId = option.ProductsId, Name = option.Name, UpdatedAt = option.UpdatedAt, Product = productDto, Departments = new DepartmentsDto { Active = option.Department.Active, Id = option.Department.Id, Name = option.Department.Name, Description = option.Department.Description } }); }); result.Data = complaintsOptions; } catch (Exception e) { result.Success = false; result.Message = $"Error al recuperar el listado de clientes: {e.Message}"; } return(result); }
public void Get_Calls_PagedProducts(ProductsDto productsDto, List<Product> products) { var mockRepo = new Mock<IRepository>(); mockRepo.Setup(a => a.PagedProducts(It.IsAny<int>(), It.IsAny<int>())) .Returns(products); var sut = new ProductsService { Repository = mockRepo.Object }; var response = sut.Get(productsDto); mockRepo.Verify(a => a.PagedProducts(It.IsAny<int>(), It.IsAny<int>()), Times.AtLeastOnce()); }