/// <summary> /// Fills the products. /// </summary> /// <param name="productCategory">The product category.</param> private void FillProducts(ProductCategoryDTO productCategory) { LstProduct = new ObservableCollection <ProductDTO>(from item in ServiceFactory.ServiceClient.GetProductByCategory(productCategory.Id) select item); OpenLooseCatPopupIsOpen = false; FirstPopupIsOpen = false; }
/// <summary> /// Save Category details in database /// </summary> /// <param name="categoryDetails">Category details to be saved</param> /// <returns>returns boolean value indicating if the records are saved in database</returns> bool ICategoryService.SaveCategoryDetails(ProductCategoryDTO categoryDetails) { product_category categoryEntity = new product_category(); ObjectMapper.Map(categoryDetails, categoryEntity); return(CategoryRepository.Save(categoryEntity)); }
public IActionResult DeleteProductCategory([FromBody] ProductCategoryDTO request) { var response = new OperationResponse <ICollection>(); try { var result = _categoriesService.DeleteProductCategory(request.Tasks); if (result.Any(fn => !string.IsNullOrEmpty(fn.Message))) { response.State = ResponseState.ValidationError; response.Data = result.ToList(); return(new JsonResult(response)); } else { response.State = ResponseState.Success; } } catch (Exception exception) { response.State = ResponseState.Error; response.Messages.Add(exception.Message); _logger.LogError(exception, "Error in DeleteProductCategory ==>" + exception.StackTrace, request); } return(new JsonResult(response)); }
public async Task <IActionResult> PutProductCategory(int id, ProductCategoryDTO productCategoryDTO) { if (id != productCategoryDTO.Id) { return(BadRequest()); } var productCategory = _mapper.Map <ProductCategory>(productCategoryDTO); _context.Entry(productCategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductCategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private IList <ProductCategoryDTO> GetFullTree(int?exceptProductCategoryId) { IEnumerable <ProductCategory> fullDataWithoutExceptingId = null; if (exceptProductCategoryId != null) { fullDataWithoutExceptingId = _unitOfWork.ProductCategoryRepository.Get(c => c.Id != exceptProductCategoryId).ToList(); } else { fullDataWithoutExceptingId = _unitOfWork.ProductCategoryRepository.GetAll().ToList(); } var filteredData = fullDataWithoutExceptingId.Where(c => c.ParentId == null); var filteredDtos = _mapper.Map <IEnumerable <ProductCategory>, IList <ProductCategoryDTO> >(filteredData); if (filteredDtos != null) { var emptyItem = new ProductCategoryDTO { Id = 0, Name = "--- Select ---" }; filteredDtos.Insert(0, emptyItem); } return(filteredDtos); }
public bool Update(ProductCategoryDTO dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } var entity = _unitOfWork.ProductCategoryRepository.GetById(dto.Id); if (entity == null) { return(false); } entity = _mapper.Map <ProductCategoryDTO, ProductCategory>(dto, entity, (options) => { //options.ConfigureMap().ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate)); ///options.ConfigureMap().ForSourceMember(x => x.CreatedDate, opt => opt.Ignore()); //options.ConfigureMap().ForMember(x => x.CreatedBy, opt => opt.Ignore()); //options.ConfigureMap().ForMember(x => x.CreatedDate, opt => opt.Ignore()); }); if (entity.ParentId <= 0) { entity.ParentId = null; } entity.ModifiedDate = DateTime.Now; _unitOfWork.ProductCategoryRepository.Update(entity); _unitOfWork.Commit(); return(true); }
public void UpdateCategory(ProductCategoryDTO category) { uow.Categories.Update(new ProductCategories { Name = category.Name, Id = category.Id }); uow.Save(); }
public void CreateCategory(ProductCategoryDTO category) { uow.Categories.Create(new ProductCategories { Name = category.Name }); uow.Save(); }
public static ProductCategoryDTO ConvertToProductCategoryDTO(ProductCategory productCategory) { ProductCategoryDTO productCategoryDTO = new ProductCategoryDTO(); productCategoryDTO.CategoryId = productCategory.CategoryId; productCategoryDTO.CategoryName = productCategory.CategoryName; return(productCategoryDTO); }
public ActionResult DeleteProductCategory(ProductCategoryDTO Ic) { var c = mmsMasters.DeleteProductCategory(Ic.CategoryId); return(new JsonResult { Data = c, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult CheckProductCategory(ProductCategoryDTO Ic) { int c = mmsMasters.CheckProductCategory(Ic); return(new JsonResult { Data = c, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ProductCategoryDTO GetProductsInCategory() { ProductCategory productCategory = _productCategoryRepository.Get(includes: i => i.Products) .FirstOrDefault(); ProductCategoryDTO mapped = _myMapper.MapTo <ProductCategoryDTO, ProductCategory>(productCategory); return(mapped); }
public async Task <ActionResult <ProductCategory> > PostProductCategory(ProductCategoryDTO newProductCategoryDTO) { ProductCategory newProductCategory = _mapper.Map <ProductCategory>(newProductCategoryDTO); _context.ProductCategories.Add(newProductCategory); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(PostProductCategory), newProductCategoryDTO)); }
public ActionResult SaveProductCategory(ProductCategoryDTO Ic) { Ic.statusid = 1; Ic.createdby = Convert.ToInt64(Session["UserId"]); int isSaved = mmsMasters.SaveProductCategory(Ic); return(new JsonResult { Data = isSaved, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public async Task <IActionResult> RemoveProduct(ProductCategoryDTO dto) { var category = await context.Categories.SingleOrDefaultAsync(cat => cat.Id == dto.CategoryId); var product = await context.Products.SingleOrDefaultAsync(prod => prod.Id == dto.ProductId); category.Products.Remove(product); await context.SaveChangesAsync(); return(Ok()); }
/// <summary> /// Registers product into two different ways: /// 1) By all values of "product" (including reference value, like foreign keys), if two last params leave optional. /// 2) By all non-reference values of "product" and all "category" and "vendor" values /// </summary> /// <param name="product">Product to add</param> /// <param name="category">Optional param of category which product is related</param> /// <param name="vendor">Optional param of vendor which product is related</param> public void RegisterProduct(ProductDTO product, ProductCategoryDTO category = null, VendorDTO vendor = null) { UnitOfWork.Products.Create(new Product { GTIN = product.GTIN, Name = product.Name, Description = product.Description, Price = product.Price, CategoryId = (category == null) ? product.CategoryId : category.Id, VendorId = (vendor == null) ? product.VendorId : vendor.Id, }); UnitOfWork.SaveChanges(); }
public IActionResult Create([FromBody] ProductCategoryDTO productCategoryDTO) { ProductCategory productCategory = new ProductCategory(); productCategory.ProductCategoryName = productCategoryDTO.ProductCategoryName; //productCategory.CreatedBy = User.Identity.Name; productCategory.CreatedBy = "Admin"; productCategory.CreatedDate = DateTime.Now; var productCategoryEntity = _productCategoryService.Create(productCategory); var productCategories = _mapper.Map <ProductCategoryDTO>(productCategoryEntity); return(Ok(productCategory)); }
public async Task <IActionResult> Create([FromBody] ProductCategoryDTO productCategory) { if (!ModelState.IsValid) { return(BadRequest("invalid model state")); } var category = _mapper.Map <ProductCategory>(productCategory); var r = await _dbContext.ProductCategories.AddAsync(category); await _dbContext.SaveChangesAsync(); return(Ok(_mapper.Map <ProductCategoryDTO>(category))); }
public long Save(ProductCategoryDTO pProductCategoryDTO) { long Result = 0; if (pProductCategoryDTO.ID != 0) { Result = new ProductCategoryService().Edit(pProductCategoryDTO); } else { Result = new ProductCategoryService().Add(pProductCategoryDTO); } return(Result); }
/// <summary> /// Получение категории продукта по Id /// </summary> /// <param name="productCategoryId">Id категории продукта</param> /// <returns></returns> public ProductCategoryDTO Get(int productCategoryId) { var result = new ProductCategoryDTO(); var url = new Uri($"{this.url}/category/{productCategoryId}"); var request = WebRequest.Create(url); var response = request.GetResponse(); using (var stream = response.GetResponseStream()) { var reader = new StreamReader(stream); var json = reader.ReadToEnd(); result = JsonConvert.DeserializeObject <ProductCategoryDTO>(json); } return(result); }
public void RemoveCategory(ProductCategoryDTO category) { var validationErrors = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(category); if (!System.ComponentModel.DataAnnotations.Validator.TryValidateObject(category, validationContext, validationErrors, true)) { throw new ArgumentException($"Wrong input data: {string.Join(", ", validationErrors)}"); } UnitOfWork.ProductCategories.Delete(new ProductCategory { Id = category.Id, Name = category.Name }); UnitOfWork.SaveChanges(); }
public ProductDTO GetProduct(int id) { var product = uow.Products.Get(id); var tempCategory = new ProductCategoryDTO(); if (product == null) { throw new ValidationException("Товар несуществует", ""); } tempCategory.Id = uow.Categories.Get(product.CategoryId).Id; tempCategory.Name = uow.Categories.Get(product.CategoryId).Name; return(new ProductDTO { Id = product.Id, Category = tempCategory, Description = product.Description, Name = product.Name, Price = product.Price }); }
public async Task <ProductCategoryDTO> GetDetailProductCategory(int ProductCategoryId) { ProductCategoryDTO output = new ProductCategoryDTO(); string apiUrl = $"/api/v1/ProductCategory/GetDetailProductCategory"; string paramRequest = $"?ProductCategoryId={ProductCategoryId}"; var response = await _client.GetAsync(apiUrl + paramRequest); if (response.IsSuccessStatusCode) { string responseStream = await response.Content.ReadAsStringAsync(); output = JsonConvert.DeserializeObject <ProductCategoryDTO>(responseStream); } return(output); }
public ProductDTO FindProduct(ProductDTO product) { Func <Product, bool> FindProduct = d => d.Name == product.Name || d.Description == product.Description || d.Price == product.Price; var founded = uow.Products.Find(FindProduct).First(); var tempCategory = new ProductCategoryDTO(); if (founded == null) { throw new ValidationException("Не найден", ""); } tempCategory.Id = uow.Categories.Get(founded.CategoryId).Id; tempCategory.Name = uow.Categories.Get(founded.CategoryId).Name; return(new ProductDTO { Id = founded.Id, Category = tempCategory, Description = founded.Description, Name = founded.Name, Price = founded.Price }); }
public async Task <Result> Handle(Request request, CancellationToken cancellationToken) { var categoryDTOs = _db.ProductCategories; var categories = new List <ProductCategoryDTO>(); foreach (var categoryDTO in categoryDTOs) { var category = new ProductCategoryDTO(categoryDTO.Id, categoryDTO.Name); categories.Add(category); } var result = new Result(categories); return(result); }
/// <summary> /// The GetProductCategory /// </summary> /// <param name="id">The id<see cref="object"/></param> /// <param name="transaction">The transaction<see cref="TransactionalInformation"/></param> /// <returns>The <see cref="ProductCategoryDTO"/></returns> public ProductCategoryDTO GetProductCategory(object id, out TransactionalInformation transaction) { transaction = new TransactionalInformation(); ProductCategoryDTO productCategory = new ProductCategoryDTO(); try { _dataService.CreateSession(); var param = new DynamicParameters(); param.Add("@ID", id); var item = _dataService.ProductCategoryRepository.GetById(ProductCategoryScript.GetById, param, CommandType.Text); productCategory.ID = item.ID; productCategory.Name = item.Name; productCategory.Alias = item.Alias; productCategory.Image = item.Image; productCategory.Description = item.Description; productCategory.HomeFlag = item.HomeFlag; productCategory.CreatedDate = item.CreatedDate; productCategory.CreatedBy = item.CreatedBy; productCategory.UpdatedDate = item.UpdatedDate; productCategory.UpdatedBy = item.UpdatedBy; productCategory.MetaKeyword = item.MetaKeyword; productCategory.MetaDescription = item.Description; productCategory.Status = item.Status; transaction.ReturnStatus = true; } catch (Exception ex) { string errorMessage = ex.Message; transaction.ReturnMessage.Add(errorMessage); transaction.ReturnStatus = false; } finally { _dataService.CloseSession(); } return(productCategory); }
public long Edit(ProductCategoryDTO pProductCategoryDTO) { long ProductCategoryID = 0; using (var Context = new BaseContext()) { var ProductCategory = Context.ProductCategories.FirstOrDefault(a => a.ID == pProductCategoryDTO.ID); if (ProductCategory != null) { ProductCategory.Title = pProductCategoryDTO.Title; ProductCategory.ParentID = pProductCategoryDTO.ParentID; Context.SaveChanges(); ProductCategoryID = ProductCategory.ID; } } return(ProductCategoryID); }
public long Add(ProductCategoryDTO pProductCategoryDTO) { long ProductCategoryID = 0; using (var Context = new BaseContext()) { var ProductCategory = new ProductCategoryModel { Title = pProductCategoryDTO.Title, ParentID = pProductCategoryDTO.ParentID, }; Context.ProductCategories.Add(ProductCategory); Context.SaveChanges(); ProductCategoryID = ProductCategory.ID; } return(ProductCategoryID); }
/// <summary> /// Обновление информации о категории продукта /// </summary> /// <param name="model">Модель категории продукта</param> /// <returns></returns> public bool Update(ProductCategoryDTO model) { var url = new Uri($"{this.url}/category/update"); var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json"; var json = JsonConvert.SerializeObject(model); using (var stream = new StreamWriter(request.GetRequestStream())) { stream.Write(json); stream.Close(); } var response = (HttpWebResponse)request.GetResponse(); return(response.StatusCode == HttpStatusCode.OK ? true : false); }
public async Task <ProductCategoryDTO> GetDetailProductCategory(int ProductCategoryId) { var output = new ProductCategoryDTO(); //var cacheKey = $"ProductCategory_GetDetailProductCategory{ProductCategoryId}"; //var redisEncode = await _distributedCache.GetStringAsync(cacheKey); //if (redisEncode != null) //{ // output = JsonConvert.DeserializeObject<ProductCategoryDTO>(redisEncode); //} //else //{ var result = await _repoWrapper.ProductCategory.SingleOrDefaultAsync(p => p.ProductCategory_ID == ProductCategoryId); output = _mapper.Map <ProductCategoryDTO>(result); // await _distributedCache.SetStringAsync(cacheKey, JsonConvert.SerializeObject(output), Utils.Util.RedisOptions()); //} return(output); }
/// <summary> /// Fills the products. /// </summary> /// <param name="productCategory">The product category.</param> private void FillProducts(ProductCategoryDTO productCategory) { LstProduct = new ObservableCollection<ProductDTO>(from item in ServiceFactory.ServiceClient.GetProductByCategory(productCategory.Id) select item); OpenLooseCatPopupIsOpen = false; FirstPopupIsOpen = false; }