public async Task <Guid> CreateAsync(SubCategoryDTO subCategoryDTO) { Guid id = Guid.NewGuid(); await _context.SubCategory.AddAsync(new Data.Entities.SubCategory { Id = id, Name = subCategoryDTO.Name, CategoryId = subCategoryDTO.CategoryId, Description = subCategoryDTO.Description, CreatedDate = DateTime.Now, CreatedBy = subCategoryDTO.CreatedBy, }); try { var response = await _context.SaveChangesAsync(); if (response > 0) { return(id); } else { return(Guid.Empty); } } catch (Exception ex) { _logger.LogError("There was an exception when attempting to create a SubCategory.", ex); return(Guid.Empty); } }
public ExecuteResult InsertSubCategory(InsertSubCategory insertSubCategory) { SubCategoryDTO subCategoryDTO = new SubCategoryDTO().CopyPropertiesFrom(insertSubCategory); ExecuteResultDTO executeResultDTO = subCategoryRepository.InsertSubCategory(subCategoryDTO); return(new ExecuteResult().CopyPropertiesFrom(executeResultDTO)); }
public ExecuteResult UpdateSubCategory(UpdateSubCategory updateSubCategory) { SubCategoryDTO subCategoryDTO = new SubCategoryDTO().CopyPropertiesFrom(updateSubCategory); ExecuteResultDTO executeResultDTO = subCategoryRepository.UpdateSubCategory(subCategoryDTO); return(new ExecuteResult().CopyPropertiesFrom(executeResultDTO)); }
public static SUBCATEGORY ToSubCategory(SubCategoryDTO pSubCategoryDTO) { SUBCATEGORY subCategory = new SUBCATEGORY(); subCategory.Id = pSubCategoryDTO.Id; subCategory.CategoryId = pSubCategoryDTO.CategoryId; subCategory.Name = pSubCategoryDTO.Name; return(subCategory); }
public static SubCategoryDTO ToSubCategoryDTO(SUBCATEGORY pSubCategory) { SubCategoryDTO subCategoryDTO = new SubCategoryDTO(); subCategoryDTO.Id = pSubCategory.Id; subCategoryDTO.CategoryId = (int)pSubCategory.CategoryId; subCategoryDTO.Name = pSubCategory.Name; return(subCategoryDTO); }
public SubCategory CastToDAL(SubCategoryDTO s) { return(new SubCategory() { subCategoryId = s.subCategoryId, subCategoyName = s.subCategoyName, Category = db.Categories.Where(a => a.categoryId == s.categoryId).FirstOrDefault(), }); }
public ActionResult Edit(SubCategoryDTO subCategory) { if (ModelState.IsValid) { subCategoryService.AddOrUpdate(subCategory); return(RedirectToAction("IndexHtmlAction")); } return(View("Edit")); }
public ActionResult Update(SubCategoryDTO data) { SubCategory sub = _subCategoryService.GetById(data.ID); sub.Name = data.Name; sub.Description = data.Description; sub.CategoryID = data.CategoryID; _subCategoryService.Update(sub); return(Redirect("/Admin/SubCategory/List")); }
public async Task <ActionResult <SubCategoryDTO> > GetById(Guid id) { SubCategoryDTO subSubCategory = await _subSubCategoryService.GetByIdAsync(id); if (subSubCategory.Id == Guid.Empty) { return(NotFound()); } return(Ok(subSubCategory)); }
//Chuyển danh sách đối tượng Data sang danh sách đối tượng Business public static List <SubCategoryDTO> SubCategoryDTOList(List <SUBCATEGORY> SubCategoryList) { List <SubCategoryDTO> subCategoryDTOList = new List <SubCategoryDTO>(); foreach (SUBCATEGORY item in SubCategoryList) { SubCategoryDTO subCategoryDTO = ToSubCategoryDTO(item); subCategoryDTOList.Add(subCategoryDTO); } return(subCategoryDTOList); }
public async IAsyncEnumerable <SubCategoryDTO> GetAllAsync() { await foreach (var subCategory in _context.SubCategory.AsAsyncEnumerable()) { if (subCategory.DeletedDate is null) { SubCategoryDTO subCategoryDTO = CloneSubCategoryEntity(subCategory); yield return(subCategoryDTO); } } }
public ActionResult Delete(int id) { try { SubCategoryDTO subCategory = subCategoryService.Get(id); subCategoryService.Delete(subCategory); return(Json("OK")); } catch { return(Json("Error")); } }
public async Task <IActionResult> EditSubCategory([FromBody] SubCategoryDTO subCategoryDTO) { try { var subCategories = _mapper.Map <SubCategoria>(subCategoryDTO); await _subCategoryServices.EditSubCategory(subCategories); return(StatusCode(StatusCodes.Status201Created, subCategories)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message })); } }
public ActionResult UploadPhoto(HttpPostedFileBase fileUpload) { string Id = Request.Params["id"]; if (fileUpload != null) { SubCategoryDTO subCategory = subCategoryService.Get(Convert.ToInt32(Id)); subCategory.SubCategoryPathPhoto = "/Images/" + fileUpload.FileName; subCategoryService.AddOrUpdate(subCategory); } string path = Path.Combine(Server.MapPath("~/Images/"), fileUpload.FileName); fileUpload.SaveAs(path); return(RedirectToAction("Edit", "SubCategory", new { id = Convert.ToInt32(Id) })); }
public async IAsyncEnumerable <SubCategoryDTO> GetByCategoryAsync(Guid categoryId) { List <Data.Entities.SubCategory> subCategoryList = await _context.SubCategory.Where(x => x.CategoryId == categoryId).ToListAsync(); foreach (var subCategory in subCategoryList) { if (subCategory.DeletedDate is null) { SubCategoryDTO subCategoryDTO = CloneSubCategoryEntity(subCategory); yield return(subCategoryDTO); } } ; }
public async Task <ActionResult> Create([FromBody] SubCategoryDTO subSubCategoryDTO) { Guid id = await _subSubCategoryService.CreateAsync(subSubCategoryDTO); if (id == Guid.Empty) { return(StatusCode(303)); } return(Created( new Uri( string.Concat(Request.Path.ToString().Remove(Request.Path.ToString().Length - 6, 6), $"GetById/{id}"), UriKind.Relative), id)); }
public bool AddSubCategory(SubCategoryDTO pSubCategoryDTO) { using (db = new MobileEntities()) { SUBCATEGORY subCategory = DALUtilitiesMethod.ToSubCategory(pSubCategoryDTO); try { db.SUBCATEGORies.Add(subCategory); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public void Update(SubCategoryDTO dtoObject) { try { _unitOfWorkAsync.BeginTransaction(); SubCategory subCategory = new SubCategory(); Mapper.Map <SubCategoryDTO, SubCategory>(dtoObject, subCategory); Update(subCategory); _unitOfWorkAsync.SaveChanges(); _unitOfWorkAsync.Commit(); } catch (Exception ex) { _unitOfWorkAsync.Rollback(); throw ex; } }
public async Task <IActionResult> AddSubCategory([FromBody] SubCategoryDTO subCategoryDTO) { try { var subCategory = _mapper.Map <SubCategoria>(subCategoryDTO); var resp = await _subCategoryServices.AddSubCategory(subCategory); if (resp == null) { return(StatusCode(StatusCodes.Status404NotFound, resp)); } return(StatusCode(StatusCodes.Status201Created, subCategory)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public SubCategoryDTO CloneSubCategoryEntity(Data.Entities.SubCategory subCategory) { SubCategoryDTO subCategoryDTO = new SubCategoryDTO { Id = subCategory.Id, CategoryId = subCategory.CategoryId, Name = subCategory.Name, Description = subCategory.Description, CreatedDate = subCategory.CreatedDate, CreatedBy = subCategory.CreatedBy, UpdatedDate = subCategory.UpdatedDate, UpdatedBy = subCategory.UpdatedBy, DeletedDate = subCategory.DeletedDate, DeletedBy = subCategory.DeletedBy, }; return(subCategoryDTO); }
private List <ProductDetailDTO> GetProductDetailsFromSubCategory(SubCategoryDTO subCategory, int orderIndex) { var products = subCategory.Products; List <ProductDetailDTO> productDetailList = new List <ProductDetailDTO>(); foreach (var product in products) { foreach (var productDetail in product.ProductDetails) { productDetailList.Add(productDetail); } } var productDetailEnumerable = (IEnumerable <ProductDetailDTO>)productDetailList; return(OrderProductDetails(productDetailEnumerable, orderIndex)); }
public bool EditSubCategory(SubCategoryDTO pSubCategoryDTO) { using (db = new MobileEntities()) { SUBCATEGORY subCategory = db.SUBCATEGORies.SingleOrDefault(n => n.Id == pSubCategoryDTO.Id); if (subCategory == null) { return(false); } try { subCategory.CategoryId = pSubCategoryDTO.CategoryId; subCategory.Name = pSubCategoryDTO.Name; db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public async Task <SubCategory> CreateSubCategory(SubCategoryDTO subcategoryDTO) { Category category = await _context.Categories.FindAsync(subcategoryDTO.CategoryId); if (category != null) { var subcategory = new SubCategory() { SubCategoryName = subcategoryDTO.SubCategoryName, Category = category, CategoryId = subcategoryDTO.CategoryId }; _context.Subcategories.Add(subcategory); await _context.SaveChangesAsync(); return(subcategory); } return(null); }
public async Task Subcategory_Create_Response() { //Arrange var dbContext = await GetDataContext(); var controller = new SubCategoryController(dbContext); //Act var subcategoryForAdding = new SubCategoryDTO() { SubCategoryName = "New Subcategory", CategoryId = 8 }; var response = controller.CreateSubCategory(subcategoryForAdding).Result; //Assert Assert.Equal(response.SubCategoryName, subcategoryForAdding.SubCategoryName); int deletingId = response.Id; var subcategoryResponse1 = controller.DeleteSubCategory(deletingId).Result; //Assert Assert.Equal(subcategoryResponse1, deletingId); }
// Thêm public bool AddSubCategory(SubCategoryDTO pSubCategoryDTO) { return(service.AddSubCategory(pSubCategoryDTO)); }
//Sửa public bool EditSubCategory(SubCategoryDTO pSubCategoryDTO) { return(service.EditSubCategory(pSubCategoryDTO)); }
public SubCategoryVM() { Categories = new List <Category>(); SubCategory = new SubCategoryDTO(); }
private void btnLuu_Click(object sender, EventArgs e) { var index = dgvListSubCategory.CurrentCell.RowIndex; _SubCategoryBusiness = new SubCategoryBusiness(); int ma = -1; bool kiemTra = false; if (txtName.Text == "") { MessageBox.Show("Tên Loại Không Được Trống!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if ((int)cbNameCategory.SelectedValue == -1) { MessageBox.Show("Vui lòng chọn danh mục!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #region Lưu khi thêm else if (g == 1) { SubCategoryDTO subCategory = new SubCategoryDTO(); subCategory.Name = txtName.Text.ToString().Trim(); subCategory.CategoryId = (int)cbNameCategory.SelectedValue; kiemTra = _SubCategoryBusiness.ExisSubName(txtName.Text.ToString(), ma, (int)cbNameCategory.SelectedValue); if (kiemTra == false) { MessageBox.Show("Tên loại thuộc danh mục này đã tồn tại! Vui Lòng Chọn Tên Khác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (_SubCategoryBusiness.AddSubCategory(subCategory)) { MessageBox.Show("Thêm mới thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadData(); } else { MessageBox.Show("Thêm mới không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } #endregion #region Lưu khi sửa else if (g == 2) { SubCategoryDTO subCategory = _lstSubCategory.ElementAtOrDefault(index); subCategory.Name = txtName.Text.ToString().Trim(); subCategory.CategoryId = (int)cbNameCategory.SelectedValue; kiemTra = _SubCategoryBusiness.ExisSubName(txtName.Text.ToString(), int.Parse(dgvListSubCategory.Rows[index].Cells[0].Value.ToString()), (int)cbNameCategory.SelectedValue); if (kiemTra == false) { MessageBox.Show("Tên loại thuộc danh mục này đã tồn tại! Vui Lòng Chọn Tên Khác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (_SubCategoryBusiness.EditSubCategory(subCategory)) { MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadData(); } else { MessageBox.Show("Sửa không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } #endregion DieuKhien((int)DIEUKHIEN.MO); g = 0; }