public static ResponseViewModel <ProductAttribute> AddProductAttribute(ProductAttributeViewModel viewModel) { ResponseViewModel <ProductAttribute> responseViewModel = new ResponseViewModel <ProductAttribute>(); ProductAttribute productAtribute = new ProductAttribute(); productAtribute.Name = viewModel.attributeName; productAtribute.ProductCategoryID = viewModel.productCategoryId; productAtribute.ProductSubCategoryID = viewModel.productSubCategoryId; using (EcommerceEntities entities = new EcommerceEntities()) { if (CheckDuplicate(productAtribute)) { responseViewModel.errorViewModel = new ErrorViewModel(); responseViewModel.errorViewModel.statusCode = 400; } else { entities.ProductAttributes.Add(productAtribute); entities.SaveChanges(); ProductAttributeManager.AddOption(viewModel.options, productAtribute.ID); responseViewModel.Data = productAtribute; entities.SaveChanges(); } } return(responseViewModel); }
public async Task <IHttpActionResult> Post(ProductAttributeViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var stf = await _productAttributeService.InsertAsync(model, GetCurrentUserID()); _unitOfWorkAsync.Commit(); var resultObject = new ProductAttributeViewModel() { ID = stf.Id, Name = stf.Name, ProductName = stf.ProductType.Name, ProductCode = stf.ProductType.Code }; return(Created(resultObject)); } catch (Exception ex) { throw ex; } }
public void UpdateProductAttribute(ProductAttributeViewModel viewModel) { SqlDb_Ultis.ExeNonStored("Product_AttributeUpDate", "@Id", viewModel.Id, "@AttributeName", viewModel.AttributeName, "@AttributeType", viewModel.AttributeType, "@Status", viewModel.Status); }
public async Task <IResult> ListAttributes(DataHelperModel dataHelper, bool getAll) { var result = new Result { Operation = Operation.Read, Status = Status.Success }; try { var listAttr = _productAttributeRepository.ListAttributes(dataHelper.Search, getAll); if (!getAll) { var list = DataSortExtention.SortBy(listAttr, dataHelper.SortColumn, dataHelper.SortOrder); var resultCount = list.Count(); var pagedList = DataCount.Page(list, dataHelper.PageNumber, dataHelper.PageSize); var resultList = await pagedList.ToListAsync(); var pdtAttrViewModels = new List <ProductAttributeViewModel>(); pdtAttrViewModels = resultList.Select(p => { var pdtAttrViewModel = new ProductAttributeViewModel(); pdtAttrViewModel.MapFromModel(p); return(pdtAttrViewModel); }).ToList(); ResultModel resultModel = new ResultModel(); resultModel.ProductAttributeResult = pdtAttrViewModels; resultModel.TotalCount = resultCount; if (resultList.Count == 0) { result.Status = Status.Fail; result.StatusCode = HttpStatusCode.BadRequest; result.Message = "No records present."; return(result); } result.Body = resultModel; } else { var attributeList = await listAttr.ToListAsync(); result.Body = attributeList; } result.Status = Status.Success; result.StatusCode = HttpStatusCode.OK; return(result); } catch (Exception e) { result.Status = Status.Error; result.Message = e.Message; result.StatusCode = HttpStatusCode.InternalServerError; return(result); } }
public ProductAttribute Insert(ProductAttributeViewModel model, string CurrentId) { var data = new ProductAttribute(); data.Name = model.Name; data.ProductType = _productTypeService.Find(model.ProductTypeID); data.CreatDate = DateTime.Now; data.LastModifiedDate = DateTime.Now; base.Insert(data); return(data); }
public ProductAttributeViewModel GetProductAttributeById(Guid Id) { DataTable dtb = SqlDb_Ultis.ExeStoredToDataTable("Product_AttributeSelectByID", "@Id", Id); ProductAttributeViewModel role = new ProductAttributeViewModel(); foreach (DataRow item in dtb.Rows) { role = Ultis.GetItem <ProductAttributeViewModel>(item); } return(role); }
public IHttpActionResult UpdateProductCategory([FromBody] ProductAttributeViewModel productAttribute) { try { return(Ok(ProductAttributeManager.UpdateProductAttribute(productAttribute))); } catch (Exception exception) { return(InternalServerError(exception)); } }
public IHttpActionResult AddProductAttribute([FromBody] ProductAttributeViewModel viewModel) { try { return(Ok(ProductAttributeManager.AddProductAttribute(viewModel))); } catch (Exception exception) { return(InternalServerError(exception)); } }
public async Task <ProductAttributeViewModel> UpdateAsync(ProductAttributeViewModel model) { try { await Task.Run(() => Update(model)); return(model); } catch (Exception e) { throw (e); } }
public async Task <ActionResult <IResult> > InsertAttribute([FromBody] ProductAttribute productAttribute) { var result = new Result { Operation = Operation.Create, Status = Status.Success }; try { if (!ModelState.IsValid) { result.Status = Status.Success; result.StatusCode = HttpStatusCode.BadRequest; return(StatusCode((int)result.StatusCode, result)); } var attributeNameCheck = await context.ProductAttributes.Where(x => x.AttributeName == productAttribute.AttributeName).ToListAsync(); if (attributeNameCheck.Count() != 0) { result.Status = Status.Fail; result.StatusCode = HttpStatusCode.BadRequest; result.Message = "isPresent"; return(StatusCode((int)result.StatusCode, result)); } productAttribute.CreatedDate = DateTime.Now; productAttribute.CreatedBy = helper.GetSpecificClaim("ID"); context.ProductAttributes.Add(productAttribute); await context.SaveChangesAsync(); ProductAttributeViewModel attributeViewModel = new ProductAttributeViewModel() { CreatedUser = helper.GetSpecificClaim("Name") }; result.Status = Status.Success; result.StatusCode = HttpStatusCode.OK; result.Body = productAttribute; return(StatusCode((int)result.StatusCode, result)); } catch (Exception e) { result.Status = Status.Error; result.Message = e.Message; result.StatusCode = HttpStatusCode.InternalServerError; return(StatusCode((int)result.StatusCode, result)); } }
public async Task <IActionResult> AddEditProductAttribute(long?id, ProductAttributeViewModel productAttributeViewModel) { try { if (productAttributeViewModel == null) { _logger.LogInformation(LogMessageConstant.ItemNotFound, productAttributeViewModel); return(NotFound()); } if (ModelState.IsValid) { bool isNew = !id.HasValue; if (isNew) { var productAttribute = _mapper.Map <ProductAttribute>(productAttributeViewModel); await _uow.ProductAttributes.AddAsync(productAttribute); _logger.LogInformation(LogMessageConstant.Added, productAttribute.Name); } else { var productAttribute = _mapper.Map <ProductAttribute>(productAttributeViewModel); await _uow.ProductAttributes.UpdateAsync(id.Value, productAttribute); _logger.LogInformation(LogMessageConstant.Updated, productAttribute.Name); } } } catch (DbUpdateConcurrencyException ce) { var isExist = await _uow.ProductAttributes.GetAsync(id.Value); if (isExist == null) { _logger.LogWarning(LogMessageConstant.IdNotFound, id); return(NotFound()); } else { _logger.LogError(ce.Message, id); } } catch (Exception ex) { _logger.LogError(ex.Message, ex.StackTrace); } return(RedirectToAction(nameof(Index))); }
public bool Update(ProductAttributeViewModel model) { var data = Find(model.ID); if (data != null) { data.Name = model.Name; data.LastModifiedDate = DateTime.Now; return(true); } else { throw new Exception("Không tìm thấy thuộc tính sản phẩm"); } }
/// <summary> /// Edit Product Attribute /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <IActionResult> Edit(int id) { ProductAttributeViewModel model = await generateAPIResponse.ProductAttributeViewRepo.GetByID("ProductAttribute/GetAttributesByID", id); if (model != null) { model.CurrencyList = GetCurrencies(); model.ProductThicknessList = GetProductThickness(id); return(View("Create", model)); } else { return(RedirectToAction("Index")); } }
public async Task <IResult> Update(ProductAttributeViewModel productAttribute) { var result = new Result { Operation = Operation.Update, Status = Status.Success }; try { var attributeObj = await _productAttributeRepository.GetAttribute(productAttribute.AttributeId); if (attributeObj == null) { result.Status = Status.Fail; result.StatusCode = HttpStatusCode.BadRequest; result.Message = "isEmpty"; return(result); } var attributeNameCheck = await _productAttributeRepository.CheckExistingAttribute(productAttribute.AttributeName); if (!attributeNameCheck) { result.Status = Status.Fail; result.StatusCode = HttpStatusCode.BadRequest; result.Message = "isPresent"; return(result); } ProductAttributeModel attrModel = new ProductAttributeModel(); attrModel.MapFromModel(productAttribute); attrModel.AttributeName = productAttribute.AttributeName; attrModel.ModifiedDate = DateTime.Now; attrModel.ModifiedBy = _specificClaim.GetSpecificClaim("Id"); var updateAttr = await _productAttributeRepository.UpdateAttribute(attrModel); return(updateAttr); } catch (Exception e) { result.Status = Status.Error; result.Message = e.Message; result.StatusCode = HttpStatusCode.InternalServerError; return(result); } }
public ActionResult Edit(int?Id) { if (Id == null) { return(RedirectToAction("List", "ProductAttribute")); } var model = new ProductAttributeViewModel(); if (Id > 0) { var data = _productAttributeService.GetById(Id ?? 0); model.Id = data.Id; model.Name = data.Name; model.Description = data.Description; } return(View(model)); }
public static ResponseViewModel <ProductAttribute> UpdateProductAttribute(ProductAttributeViewModel viewModel) { ResponseViewModel <ProductAttribute> responseViewModel = new ResponseViewModel <ProductAttribute>(); using (EcommerceEntities entities = new EcommerceEntities()) { ProductAttribute productAtributeDb = entities.ProductAttributes.Where(entry => entry.ID == viewModel.ID).FirstOrDefault(); productAtributeDb.Name = viewModel.attributeName; productAtributeDb.ProductCategoryID = viewModel.productCategoryId; productAtributeDb.ProductSubCategoryID = viewModel.productSubCategoryId; entities.SaveChanges(); ProductAttributeManager.AddOption(viewModel.options, productAtributeDb.ID); responseViewModel.Data = productAtributeDb; entities.SaveChanges(); return(responseViewModel); } }
public async Task <IResult> GetDetail(int id) { var result = new Result { Operation = Operation.Read, Status = Status.Success }; try { if (id != 0) { var attrModel = await _productAttributeRepository.GetAttribute(id); ProductAttributeViewModel productAttribute = new ProductAttributeViewModel(); productAttribute.MapFromModel(attrModel); if (productAttribute != null) { result.Status = Status.Success; result.StatusCode = HttpStatusCode.OK; result.Body = productAttribute; return(result); } else { result.Status = Status.Fail; result.StatusCode = HttpStatusCode.BadRequest; result.Message = "Attribute does not exist."; return(result); } } result.Status = Status.Fail; result.StatusCode = HttpStatusCode.BadRequest; result.Message = "Attribute ID is not valid."; return(result); } catch (Exception e) { result.Status = Status.Error; result.Message = e.Message; result.StatusCode = HttpStatusCode.InternalServerError; return(result); } }
public async Task <IHttpActionResult> Put(Guid key, ProductAttributeViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _productAttributeService.UpdateAsync(model); _unitOfWorkAsync.Commit(); return(Updated(model)); } catch (Exception e) { throw e; } }
public IActionResult Create(int?id, int?ProductAttributeID) { if (id != null) { ProductAttributeViewModel _productAttributeViewModel = new ProductAttributeViewModel { ProductID = id, ProductAttributeID = 0, CurrencyList = GetCurrencies(), ProductThicknessList = GetProductThickness(0) }; return(View(_productAttributeViewModel)); } else { return(null); } }
public async Task <IResult> UpdateAttribute([FromBody] ProductAttributeViewModel productAttribute) { var result = new Result { Operation = Operation.Update, Status = Status.Success }; if (!ModelState.IsValid) { result.Status = Status.Fail; result.StatusCode = HttpStatusCode.BadRequest; return(result); } var updateAttr = await _productAttributeService.Update(productAttribute); return(updateAttr); }
public async Task <IActionResult> AddEditProductAttribute(long?id) { ProductAttributeViewModel productAttributeViewModel = new ProductAttributeViewModel(); if (id.HasValue) { var productAttribute = await _uow.ProductAttributes.GetAsync(id.Value); if (productAttribute == null) { _logger.LogInformation(LogMessageConstant.ItemNotFound, productAttributeViewModel); return(NotFound()); } productAttributeViewModel = _mapper.Map <ProductAttributeViewModel>(productAttribute); } return(PartialView("~/Areas/Admin/Views/ProductAttribute/_AddEditProductAttribute.cshtml", productAttributeViewModel)); }
public static ProductAttributeViewModel GetProductAtrributeById(int id) { ResponseViewModel <List <ProductAttributeViewModel> > viewModel = new ResponseViewModel <List <ProductAttributeViewModel> >(); ProductAttributeViewModel attributeViewModel = new ProductAttributeViewModel(); using (EcommerceEntities entities = new EcommerceEntities()) { ProductAttribute productAtrribute = new ProductAttribute(); productAtrribute = entities.ProductAttributes.Where(entry => entry.ID == id).FirstOrDefault(); //List<ProductAttributeOption> options = new List<ProductAttributeOption>(); //options = entities.ProductAttributeOptions.Where(entry => entry.ProductAtrributeID == productAtrribute.ID).ToList(); //attributeViewModel.productAttribute = productAtrribute; //attributeViewModel.options = options; attributeViewModel.attributeName = productAtrribute.Name; attributeViewModel.productCategoryId = Convert.ToInt32(productAtrribute.ProductCategoryID); attributeViewModel.productSubCategoryId = Convert.ToInt32(productAtrribute.ProductSubCategoryID); } return(attributeViewModel); }
public ActionResult Create(ProductAttributeViewModel viewModel) { try { // TODO: Add insert logic here if (ModelState.IsValid) { viewModel.AttributeType = String.Empty; _iProductAttributeService.InsertProductAttribute(viewModel); return(RedirectToAction("Index")); } else { return(View(viewModel)); } } catch { return(View()); } }
/// <summary> /// Save & Update Product Attribute Details with Post & Put Methods of the Web APIs. /// </summary> /// <param name="model"></param> /// <param name="action"></param> /// <returns></returns> private async Task <IActionResult> SaveProductAttributeDetails(ProductAttributeViewModel model, String action) { try { var response = false; // Call Post Method to Create New Product Attribute Details if (action.ToLower() == "create") { model = await generateAPIResponse.ProductAttributeViewRepo.SaveModel("ProductAttribute", model); if (model.ProductAttributeID != 0) { response = true; } } // Call Put Method to Update Existing Product Attribute Details else { response = await generateAPIResponse.ProductAttributeViewRepo.Update("ProductAttribute/" + model.ProductAttributeID, model); } if (response) { TempData["Message"] = "Product Attribute record has been updated successfully."; TempData["Class"] = "text-success"; return(Ok(model.ProductAttributeID)); } else { ViewBag.Message = null; } } catch (Exception ex) { ViewBag.Message = "Something went wrong: " + ex.Message; } return(StatusCode(500)); }
public ActionResult Edit(string proAttrId, ProductAttributeViewModel viewModel) { try { // TODO: Add update logic here Guid g = Guid.Parse(proAttrId); if (ModelState.IsValid) { viewModel.Id = g; viewModel.AttributeType = String.Empty; _iProductAttributeService.UpdateProductAttribute(viewModel); return(RedirectToAction("Index")); } else { return(View(viewModel)); } } catch { return(View()); } }
public async Task <IResult> Insert(ProductAttributeViewModel productAttribute) { var result = new Result { Operation = Operation.Create, Status = Status.Success }; try { var attributeNameCheck = await _productAttributeRepository.CheckExistingAttribute(productAttribute.AttributeName); if (!attributeNameCheck) { result.Status = Status.Fail; result.StatusCode = HttpStatusCode.BadRequest; result.Message = "isPresent"; return(result); } productAttribute.CreatedDate = DateTime.Now; productAttribute.CreatedBy = _specificClaim.GetSpecificClaim("Id"); ProductAttributeModel attributeModel = new ProductAttributeModel(); attributeModel.MapFromViewModel(productAttribute); var addAttr = await _productAttributeRepository.InsertAttribute(attributeModel); return(addAttr); } catch (Exception e) { result.Status = Status.Error; result.Message = e.Message; result.StatusCode = HttpStatusCode.InternalServerError; return(result); } }
public ActionResult Edit(ProductAttributeViewModel model, bool continueEditing) { if (ModelState.IsValid) { ProductAttribute _pro = new ProductAttribute(); _pro.Id = model.Id; _pro.Name = model.Name; _pro.Description = model.Description; if (_productAttributeService.Update(_pro)) { Success("Kayit işlemi başarılı bir şekilde gerçekleşti"); } else { Danger("Kayıt işlemi sirasında bir hata gerçekleşti"); } if (continueEditing) { return(RedirectToAction("Edit", "ProductAttribute", new { Id = model.Id })); } return(RedirectToAction("List", "ProductAttribute")); } return(View(model)); }
public ActionResult Create() { var model = new ProductAttributeViewModel(); return(View(model)); }
public async Task <IActionResult> Edit(ProductAttributeViewModel model) { return(await SaveProductAttributeDetails(model, "Edit")); }
public async Task <ProductAttribute> InsertAsync(ProductAttributeViewModel model, string CurrentId) { return(await Task.Run(() => Insert(model, CurrentId))); }