public async Task <ActionResult> PositionEmporium(AddCategoryModel workPlace)
        {
            try
            {
                int?Id         = Convert.ToInt32(workPlace.EmporiaName);
                int?PositionId = Convert.ToInt32(workPlace.PositionName);
                if (Id.HasValue && PositionId.HasValue)
                {
                    bool isfound = payrollDb.EmporiumPositions
                                   .Any(x => x.EmporiumId == Id && x.PositionsId == PositionId);

                    if (!isfound)
                    {
                        EmporiumPosition emporiumPosition = new EmporiumPosition
                        {
                            EmporiumId  = (int)Id,
                            PositionsId = (int)PositionId
                        };
                        await payrollDb.EmporiumPositions.AddAsync(emporiumPosition);

                        await payrollDb.SaveChangesAsync();
                    }
                }
            }
            catch (Exception exp)
            {
                ModelState.AddModelError("", exp.Message);
            }


            return(RedirectToAction(nameof(PositionEmporium)));
        }
Exemplo n.º 2
0
        ActionOutput ICategoryManager.AddCategory(AddCategoryModel model)
        {
            ActionOutput res = new ActionOutput();

            try
            {
                var already = Context.Categories.Where(p => p.Name == model.Name).Any();
                if (!already)
                {
                    Category _category = new Category();
                    _category.Description = model.Description;
                    _category.IsDeleted   = false;
                    _category.Name        = model.Name;
                    _category.CreatedOn   = DateTime.Now;
                    Context.Categories.Add(_category);
                    Context.SaveChanges();

                    return(SuccessResponse("Category Added Successfully"));
                }
                else
                {
                    return(ErrorResponse("Category with the same name already exists."));
                }
            }
            catch (Exception ex)
            {
                return(ErrorResponse("Some Error Occurred"));
            }
        }
        public string AddSubCategory([FromBody] AddCategoryModel model)
        {
            IMongoDAL dal = new MongoDAL();

            dal.InsertCategorySubCategory(model.category, model.subcategory);
            return("OK");
        }
        public void AddCategory_ReturnCreatedItem_WhenModelStateIsValid()
        {
            //Arrange
            var dbContext = new DocumentDbContext();

            dbContext.Categories = GetQueryableMockDbSetCategory();

            var categoryRepo = new CategoryRepo(string.Empty, dbContext);
            var controller   = new CategoryController(categoryRepo);

            AddCategoryModel addCategoryModel = new AddCategoryModel()
            {
                Title = "Tình Cảm"
            };

            //Act
            var result = controller.AddCategory(addCategoryModel);

            //Assert
            Assert.IsType <OkObjectResult>(result);

            var okObjectResult = result as OkObjectResult;

            Assert.IsType <Category>(okObjectResult.Value);

            var categoryObject = okObjectResult.Value as Category;

            Assert.Equal(categoryObject.Title, addCategoryModel.Title);
        }
Exemplo n.º 5
0
        public IActionResult AddCategory(AddCategoryModel model)
        {
            if (ModelState.IsValid)
            {
                ParentCategory parentCateogory = unitOfWork.ParentCategories.Get(model.ParentCategoryId);

                if (parentCateogory != null)
                {
                    Category category = new Category()
                    {
                        CategoryName      = model.CategoryName,
                        ParentCategory    = parentCateogory,
                        ProductCategories = new List <ProductCategory>()
                    };
                    unitOfWork.Categories.Add(category);
                    unitOfWork.SaveChanges();
                    var data = new string[] { category.CategoryId.ToString(), category.CategoryName, category.ParentCategory.ParentCategoryName };
                    //var data = JsonConvert.SerializeObject(category);
                    return(Ok(data));
                }
                else
                {
                    ModelState.AddModelError("", "ParentCategory was not found!");
                }
            }
            return(BadRequest());
        }
        public async Task Add(AddCategoryModel model)
        {
            var entity = _mapper.Map <Category>(model);

            _repository.Add(entity);

            await _repository.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public void TestIf_AddCategory_InsertsCategoryInTheDatabase()
        {
            var category = new AddCategoryModel();

            this.categoryService.AddCategory(category);

            Assert.Single(this.context.Categories);
        }
Exemplo n.º 8
0
 public IActionResult Create(AddCategoryModel model)
 {
     if (!this.ModelState.IsValid)
     {
         return(this.View(model));
     }
     this.categoryService.AddCategory(model);
     return(this.RedirectToAction("All", "Category"));
 }
Exemplo n.º 9
0
        public ActionResult Add(AddCategoryModel model)
        {
            // TODO: validate

            var catId = Guid.NewGuid().ToString();

            _commandSender.Send(new AddCategory(catId, model.Title, model.ParentId));

            return(RedirectToAction(null));
        }
Exemplo n.º 10
0
        public async Task <TResult> AddAsync <TResult>(AddCategoryModel model)
        {
            var category = this.mapper.Map <Category>(model);

            await this.categoryRepository.AddAsync(category);

            await this.categoryRepository.SaveAsync();

            return(await GetAsync <TResult>(category.Id));
        }
        public async Task <IActionResult> AddCategory(AddCategoryModel model)
        {
            var secureImageUri = await this.Upload(model.ImageUpload);

            await this.categoryService.CreateCategory(model.Title, secureImageUri, model.Description);

            return(this.RedirectToAction("Index", "Category"));

            // Controller name added just to make the code easier to understand
            // and not to be confused with the Home controller
        }
Exemplo n.º 12
0
        public void AddCategory(AddCategoryModel model)
        {
            var category = new Category
            {
                Name = model.Name
            };

            this.categoryRepository.AddAsync(category);
            this.categoryRepository.SaveChangesAsync();

            //this.categoryRepository.All().FirstOrDefault(p => p.Name == model.Name).Id;
        }
Exemplo n.º 13
0
 public ActionResult AddCategory(AddCategoryModel model)
 {
     if (categoryRepository.AddCategory(model.Name, model.Description))
     {
         return(RedirectToAction("category", "Admin"));
     }
     else
     {
         ModelState.AddModelError("", "Сталась помилка");
         return(View());
     }
 }
Exemplo n.º 14
0
        public async Task <IActionResult> AddCategory(AddCategoryModel model)
        {
            var imageUri = "/images/users/default.png";
            var category = new Category
            {
                CategoryTitle       = model.CategoryTitle,
                CategoryDescription = model.CategoryDescription,
                CategoryCreated     = DateTime.Now,
                CategoryImageUrl    = imageUri
            };
            await _categoryImplementation.Create(category);

            return(RedirectToAction("Index", "Category"));
        }
Exemplo n.º 15
0
        public IActionResult AddCategory([FromBody] AddCategoryModel addCategoryModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Category newCategory = new Category()
            {
                Title = addCategoryModel.Title
            };

            var response = _categoryRepo.AddCategory(newCategory);

            return(Ok(response));
        }
Exemplo n.º 16
0
        public IActionResult CreateCategory(AddCategoryModel model)
        {
            if (ModelState.IsValid)
            {
                AddCategoryModel category = new AddCategoryModel();

                _categoryRepository.Add(new Category {
                    Id   = model.Id,
                    Name = model.Name
                });



                return(RedirectToAction("index", "category"));
            }
            return(View(model));
        }
Exemplo n.º 17
0
        private void AddCategory(object param)
        {
            AddCategoryModel categoryModel = Controller.GetNewCategoryFromUser(Categories);

            if (categoryModel == null || categoryModel.DialogResult == false)
            {
                return;
            }

            Category category = categoryModel.Category;

            Categories.Add(category);

            SelectedCategory = category;

            //Add category to storage
            _storage.AddCategory(category);
        }
Exemplo n.º 18
0
        public async Task <IActionResult> Post([FromBody] AddCategoryModel model)
        {
            if (!ModelState.IsValid || !Guid.TryParse(model.ParentCategoryId, out Guid guid))
            {
                return(BadRequest());
            }

            var x = await _categoryService.CreateAsync(model.Name, guid);

            if (x != null)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 19
0
        public IActionResult AddCategory(AddCategoryModel category)
        {
            if (ModelState.IsValid)
            {
                Category cat = new Category();
                cat.Name      = category.Name;
                cat.parent_id = category.categories;
                cat.Desc1     = category.Desc1;
                db.Categories.Add(cat);
                db.SaveChanges();
                return(RedirectToAction("CategoryList"));
            }
            List <Category> categories = db.Categories.ToList();

            categories.Insert(0, new Category {
                Name = "Головний пункт меню", Id = 0
            });
            ViewBag.Categories = new SelectList(categories, "Id", "Name");
            return(View(category));
        }
Exemplo n.º 20
0
        public ActionResult AddCategory(AddCategoryModel model, int?id)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var _Context = new ApplicationContext())
            {
                // current admin id
                var currentAdmin = _Context.Users.Single(m => m.Email == User.Identity.Name).UserId;

                // if new category
                if (id.Equals(null))
                {
                    // add new category
                    var create = _Context.Category_Details;
                    create.Add(new Category_Details
                    {
                        Category_Name = model.Name,
                        Description   = model.Description,
                        Added_By      = currentAdmin,
                        Added_Date    = DateTime.Now,
                        IsActive      = true
                    });

                    _Context.SaveChanges();
                }
                // update existing category
                else
                {
                    var update = _Context.Category_Details.Single(m => m.Category_Id == id);
                    model.MaptoModel(update);
                    update.Modified_By   = currentAdmin;
                    update.Modified_date = DateTime.Now;

                    _Context.SaveChanges();
                }
            }
            return(RedirectToAction("ManageCategory"));
        }
Exemplo n.º 21
0
        public JsonResult Add(AddCategoryModel model)
        {
            model.AddDate = DateTime.Now;
            model.AddUser = UserInfo.CurrentUserName;
            model.Grade   = model.ParentGrade + 1;
            if (model.Grade == 3)
            {
                model.CategoryTypeModel = new CategoryTypeModel
                {
                    CategoryTypeId = MemCacheFactory.GetCurrentMemCache().Increment("logId")
                };
            }

            var result = this._categoryService.AddCategory(model);

            var opera = string.Format("添加商品分类:{0},操作结果:{1}", JsonConverts.ToJson(model), result.Messages);

            LogPackage.InserAC_OperateLog(opera, "商品分类-添加");

            return(this.Json(result));
        }
Exemplo n.º 22
0
        /// <summary>
        ///     添加类别
        /// </summary>
        /// <param name="model">类别模型</param>
        public ResultModel AddCategory(AddCategoryModel model)
        {
            var result = new ResultModel();

            using (var tx = this._database.Db.BeginTransaction())
            {
                try
                {
                    var category = tx.Category.Insert(model);
                    if (model.Category_Lang != null && model.Category_Lang.Count != 0)
                    {
                        foreach (var lang in model.Category_Lang)
                        {
                            lang.CategoryId = category.CategoryId;
                        }
                        tx.Category_Lang.Insert(model.Category_Lang);
                    }

                    if (model.Grade == 3)
                    {
                        if (model.SKU_ProductTypesModel != null)
                        {
                            model.CategoryTypeModel.CategoryId = category.CategoryId;
                            model.CategoryTypeModel.SkuTypeId  = model.SKU_ProductTypesModel.SkuTypeId;
                            tx.CategoryType.Insert(model.CategoryTypeModel);
                        }
                    }

                    tx.Commit();
                }
                catch
                {
                    tx.Rollback();
                    throw;
                }
            }

            return(result);
        }
Exemplo n.º 23
0
        public void CategoryService_GetCategoryById()
        {
            var model = new AddCategoryModel
            {
                AddDate       = DateTime.Now,
                parentId      = 0,
                AuditState    = true,
                AddUser       = "******",
                Grade         = 1,
                Place         = 0,
                Category_Lang = new List <CategoryLanguageModel>()
                {
                    new CategoryLanguageModel()
                    {
                        LanguageID   = 1,
                        CategoryName = "中文1"
                    },
                    new CategoryLanguageModel()
                    {
                        LanguageID   = 2,
                        CategoryName = "英文"
                    },
                    new CategoryLanguageModel()
                    {
                        LanguageID   = 3,
                        CategoryName = "泰文"
                    },
                }
            };

            var result = this._categoryService.AddCategory(model);

            var result1 = this._categoryService.GetCategoryById(result.Data);

            Assert.IsTrue(result1.IsValid);
        }
Exemplo n.º 24
0
 public bool CategoryExists(AddCategoryModel model)
 {
     return(this.categoryRepository.All().Any(p => p.Name == model.Name));
 }
Exemplo n.º 25
0
 public IActionResult AddDesigner(AddCategoryModel model)
 {
     _categoryService.AddDesigner(model.Name);
     return(Ok());
 }
Exemplo n.º 26
0
 public IActionResult AddMechanics(AddCategoryModel model)
 {
     _categoryService.AddMechanics(model.Name);
     return(Ok());
 }
        public async Task <IActionResult> Save(AddCategoryModel model)
        {
            await _categoryService.Add(model);

            return(Ok());
        }
Exemplo n.º 28
0
 public JsonResult AddCategory(AddCategoryModel model)
 {
     ViewBag.SelectedTab = SelectedAdminTab.Category;
     return(JsonResult(_CategoryManager.AddCategory(model)));
 }
        public async Task <ActionResult> AddPosition(AddCategoryModel workPlace)
        {
            try
            {
                if (workPlace.DepartamentId != 0)
                {
                    int?Id = Convert.ToInt32(workPlace.DepartamentId);
                    if (Id.HasValue)
                    {
                        Positions positions = new Positions
                        {
                            Name = workPlace.PositionName,
                        };
                        await payrollDb.Positions.AddAsync(positions);

                        await payrollDb.SaveChangesAsync();

                        EmployeeSalary employeeSalary = new EmployeeSalary
                        {
                            Salary      = workPlace.Salary,
                            PositionsId = positions.Id
                        };
                        await payrollDb.EmployeeSalaries.AddAsync(employeeSalary);

                        await payrollDb.SaveChangesAsync();

                        PositionsDepartament positionsDepartament = new PositionsDepartament
                        {
                            PositionsId   = positions.Id,
                            DepartamentId = (int)Id
                        };
                        await payrollDb.PositionsDepartaments.AddAsync(positionsDepartament);

                        await payrollDb.SaveChangesAsync();
                    }
                }
                else
                {
                    Positions positions = new Positions
                    {
                        Name = workPlace.PositionName,
                    };
                    await payrollDb.Positions.AddAsync(positions);

                    await payrollDb.SaveChangesAsync();

                    EmployeeSalary employeeSalary = new EmployeeSalary
                    {
                        Salary      = workPlace.Salary,
                        PositionsId = positions.Id
                    };
                    await payrollDb.EmployeeSalaries.AddAsync(employeeSalary);

                    await payrollDb.SaveChangesAsync();
                }
            }
            catch (Exception exp)
            {
                ModelState.AddModelError("", exp.Message);
            }


            return(RedirectToAction(nameof(AddPosition)));
        }
Exemplo n.º 30
0
        public IActionResult Create()
        {
            var model = new AddCategoryModel();

            return(View(model));
        }