예제 #1
0
 public Category EditCategory(Category categoryToUpdate)
 {
     categoryToUpdate.ModifiedOn = DateTime.Now;
     this.categoryRepo.Update(categoryToUpdate);
     this.categoryRepo.SaveChanges();
     return categoryToUpdate;
 }
예제 #2
0
 public Category Delete(Category categoryToDelete)
 {
     categoryToDelete.DeletedOn = DateTime.Now;
     categoryToDelete.IsDeleted = true;
     this.categoryRepo.AddDeleteFlag(categoryToDelete);
     this.categoryRepo.SaveChanges();
     return categoryToDelete;
 }
예제 #3
0
        public ActionResult AddCategory(AddCategoryViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return View(model);
            }

            var imagesToDatabase = new List<CategoryImage>();
            var categoryToDatabase = new List<Category>();

            foreach (var item in model.Images)
            {
                var current = new CategoryImage
                {
                    CategoryName = model.CategoryName,
                    FileName = item.FileName,
                    IsFrontImage = true,
                    InputStream = item.InputStream,
                    ContentLength = item.ContentLength,
                    ContentType = item.ContentType
                };
                imagesToDatabase.Add(current);
            }

            var categoryToAdd = new Category
            {
                Name = model.CategoryName,
                Description = model.CategoryDescription,
                FrontImageName = imagesToDatabase[0].FileName,
                Quantity = 0
            };
            categories.CreateCategory(categoryToAdd,imagesToDatabase);
            images.SaveImageFile(imagesToDatabase);
            images.SaveImageRecord(imagesToDatabase);

            return View("All");
        }
예제 #4
0
 public void CreateCategory(Category categoryToAdd,List<CategoryImage> images)
 {
     categoryToAdd.Images = images;
     this.categoryRepo.Add(categoryToAdd);
     this.categoryRepo.SaveChanges();
 }