public ActionResponse Update(int id, SectorSubCategoryModel model)
        {
            using (var unitWork = new UnitOfWork(context))
            {
                ActionResponse response = new ActionResponse();
                IMessageHelper mHelper;
                var            sectorSubCategoryObj = unitWork.SectorSubCategoryRepository.GetByID(id);
                if (sectorSubCategoryObj == null)
                {
                    mHelper          = new MessageHelper();
                    response.Success = false;
                    response.Message = mHelper.GetNotFound("Sector SubCategory");
                    return(response);
                }
                var sectorCategory = unitWork.SectorCategoryRepository.GetByID(model.CategoryId);
                if (sectorCategory == null)
                {
                    mHelper          = new MessageHelper();
                    response.Success = false;
                    response.Message = mHelper.GetNotFound("Sector Category");
                    return(response);
                }

                sectorSubCategoryObj.SectorCategory = sectorCategory;
                sectorSubCategoryObj.SubCategory    = model.SubCategory;
                unitWork.SectorSubCategoryRepository.Update(sectorSubCategoryObj);
                unitWork.Save();
                return(response);
            }
        }
 public ActionResponse Add(SectorSubCategoryModel model)
 {
     using (var unitWork = new UnitOfWork(context))
     {
         ActionResponse response = new ActionResponse();
         IMessageHelper msgHelper;
         try
         {
             var category = unitWork.SectorCategoryRepository.GetByID(model.CategoryId);
             if (category == null)
             {
                 msgHelper        = new MessageHelper();
                 response.Success = false;
                 response.Message = msgHelper.GetNotFound("Category");
             }
             var newSectorSubCategory = unitWork.SectorSubCategoryRepository.Insert(new EFSectorSubCategory()
             {
                 SectorCategory = category,
                 SubCategory    = model.SubCategory
             });
             response.ReturnedId = newSectorSubCategory.Id;
             unitWork.Save();
         }
         catch (Exception ex)
         {
             response.Success = false;
             response.Message = ex.Message;
         }
         return(response);
     }
 }
示例#3
0
        public IActionResult Put(int id, [FromBody] SectorSubCategoryModel sectorSubCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var response = sectorSubCategoryService.Update(id, sectorSubCategory);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response.Message));
        }
示例#4
0
        public IActionResult Post([FromBody] SectorSubCategoryModel sectorSubCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var response = sectorSubCategoryService.Add(sectorSubCategory);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response.ReturnedId));
        }