public EntityResult UpdateRegion(RegionViewModel regionModel) { try { if (regionModel == null) { throw new ArgumentNullException("regionModel"); } var currentRegion = _unitOfWork.RegionRepository.GetByID(regionModel.RegionId); if (currentRegion == null) { throw new ArgumentException("Region is not found.", "regionModel"); } //Validate Region var region = regionModel.ToRegion(); var validationResult = ValidateRegion(region); if (validationResult != null && validationResult.Count > 0) { return(EntityResult.Failed(validationResult.ToArray())); } //Update Region _unitOfWork.RegionRepository.Update(region); _unitOfWork.Save(); return(EntityResult.Success); } catch (Exception ex) { _logger.Error(ex, ex.Message); throw; } }
public ActionResult Create([FromBody] RegionViewModel vm) { var comp = vm.ToRegion(); var res = _bo.Create(comp); return(res.Success ? Ok() : InternalServerError()); }
public EntityResult AddRegion(RegionViewModel regionModel) { try { if (regionModel == null) { throw new ArgumentNullException("regionModel"); } var region = regionModel.ToRegion(); //Validate Region var validationResult = ValidateRegion(region); if (validationResult != null && validationResult.Count > 0) { return(EntityResult.Failed(validationResult.ToArray())); } //Add Region _unitOfWork.RegionRepository.Add(region); _unitOfWork.Save(); regionModel.RegionId = region.Id; return(EntityResult.Success); } catch (Exception ex) { _logger.Error(ex, ex.Message); throw; } }