Example #1
0
        public IActionResult NewBizCategory(NewBizViewModel MainVM)
        {
            if (checkLogStatus() == false)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (TryValidateModel(MainVM.CategoryVM))
            {
                string _category = Constants.UppercaseFirst(MainVM.CategoryVM.Category);
                // confirm the category does not already exist
                try
                {
                    BusCategory CheckCategory = _context.Categories.SingleOrDefault(cat => cat.Category == _category);
                    if (CheckCategory != null)
                    {
                        // the category already has an existing record; throw an error
                        AddAlreadyExistsError("BizVM.CategoryId");
                        return(RedirectToAction("NewBiz"));
                    }
                }
                catch (Exception ex)
                {
                    // there were not any matching entries
                }
                BusCategory NewCategory = new BusCategory();
                NewCategory.Category = _category;
                _context.Categories.Add(NewCategory);
                _context.SaveChanges();
            }
            return(RedirectToAction("NewBiz"));
        }
        public async Task <IHttpActionResult> PutBusCategory(BusCategory busCategory)
        {
            //var model = _mapper.Map<BusCategory>(busCategory);

            _unitOfWork.BusCategory.Update(busCategory);
            await _unitOfWork.Complete();

            return(Ok(busCategory));
        }