Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public ExecuteResult InsertSubCategory(InsertSubCategory insertSubCategory)
        {
            SubCategoryDTO   subCategoryDTO   = new SubCategoryDTO().CopyPropertiesFrom(insertSubCategory);
            ExecuteResultDTO executeResultDTO = subCategoryRepository.InsertSubCategory(subCategoryDTO);

            return(new ExecuteResult().CopyPropertiesFrom(executeResultDTO));
        }
Esempio n. 3
0
        public ExecuteResult UpdateSubCategory(UpdateSubCategory updateSubCategory)
        {
            SubCategoryDTO   subCategoryDTO   = new SubCategoryDTO().CopyPropertiesFrom(updateSubCategory);
            ExecuteResultDTO executeResultDTO = subCategoryRepository.UpdateSubCategory(subCategoryDTO);

            return(new ExecuteResult().CopyPropertiesFrom(executeResultDTO));
        }
Esempio n. 4
0
        public static SUBCATEGORY ToSubCategory(SubCategoryDTO pSubCategoryDTO)
        {
            SUBCATEGORY subCategory = new SUBCATEGORY();

            subCategory.Id         = pSubCategoryDTO.Id;
            subCategory.CategoryId = pSubCategoryDTO.CategoryId;
            subCategory.Name       = pSubCategoryDTO.Name;
            return(subCategory);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 public SubCategory CastToDAL(SubCategoryDTO s)
 {
     return(new SubCategory()
     {
         subCategoryId = s.subCategoryId,
         subCategoyName = s.subCategoyName,
         Category = db.Categories.Where(a => a.categoryId == s.categoryId).FirstOrDefault(),
     });
 }
Esempio n. 7
0
 public ActionResult Edit(SubCategoryDTO subCategory)
 {
     if (ModelState.IsValid)
     {
         subCategoryService.AddOrUpdate(subCategory);
         return(RedirectToAction("IndexHtmlAction"));
     }
     return(View("Edit"));
 }
Esempio n. 8
0
        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));
        }
Esempio n. 10
0
        //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);
        }
Esempio n. 11
0
        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);
                }
            }
        }
Esempio n. 12
0
 public ActionResult Delete(int id)
 {
     try
     {
         SubCategoryDTO subCategory = subCategoryService.Get(id);
         subCategoryService.Delete(subCategory);
         return(Json("OK"));
     }
     catch
     {
         return(Json("Error"));
     }
 }
Esempio n. 13
0
        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 }));
            }
        }
Esempio n. 14
0
        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) }));
        }
Esempio n. 15
0
        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));
        }
Esempio n. 17
0
 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);
         }
     }
 }
Esempio n. 18
0
 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;
     }
 }
Esempio n. 19
0
        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));
            }
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        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));
        }
Esempio n. 22
0
 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);
         }
     }
 }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        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);
        }
Esempio n. 25
0
 // Thêm
 public bool AddSubCategory(SubCategoryDTO pSubCategoryDTO)
 {
     return(service.AddSubCategory(pSubCategoryDTO));
 }
Esempio n. 26
0
 //Sửa
 public bool EditSubCategory(SubCategoryDTO pSubCategoryDTO)
 {
     return(service.EditSubCategory(pSubCategoryDTO));
 }
Esempio n. 27
0
 public SubCategoryVM()
 {
     Categories  = new List <Category>();
     SubCategory = new SubCategoryDTO();
 }
Esempio n. 28
0
        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;
        }