Beispiel #1
0
        public async Task <IHttpActionResult> DeleteLocation(ViewModels.Option dto)
        {
            var entity = await unitOfWork.OptionRepository.GetByID(dto.Id);

            if (entity == null)
            {
                return(NotFound());
            }



            var canDelete = unitOfWork.OptionRepository.CanDelete(entity);

            if (canDelete.Code != HttpStatusCode.OK)
            {
                return(canDelete);
            }

            unitOfWork.OptionRepository.Delete(entity);

            var saveResult = await unitOfWork.SaveAsync();

            if (saveResult.Code != HttpStatusCode.OK)
            {
                return(saveResult);
            }

            return(Ok(dto));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PostOption(ViewModels.Option dto)
        {
            // return Ok(client);
            if (dto == null)
            {
                return(Exceptions.getNullException(ModelState));
            }
            if (!ModelState.IsValid)
            {
                // return BadRequest(ModelState);
                return(Exceptions.getModelValidationException(ModelState));
            }
            var validate = unitOfWork.OptionRepository.Validate(dto);

            if (validate.Code != HttpStatusCode.OK)
            {
                return(validate);
            }

            Option entity = null;

            if (dto.Id == -1)
            {
                entity = new Option();
                unitOfWork.OptionRepository.Insert(entity);
            }

            else
            {
                entity = await unitOfWork.OptionRepository.GetByID(dto.Id);
            }

            if (entity == null)
            {
                return(Exceptions.getNotFoundException());
            }

            entity.Title      = dto.Title;
            entity.IsSystem   = (bool)dto.IsSystem;
            entity.OrderIndex = (int)dto.OrderIndex;
            entity.ParentId   = dto.ParentId;
            entity.CreatorId  = dto.CreatorId;



            var saveResult = await unitOfWork.SaveAsync();

            if (saveResult.Code != HttpStatusCode.OK)
            {
                return(saveResult);
            }

            dto.Id = entity.Id;
            return(Ok(dto));
        }
        public virtual CustomActionResult Validate(ViewModels.Option dto)
        {
            var exist = dbSet.FirstOrDefault(q => q.Id != dto.Id && q.CreatorId == dto.CreatorId && q.Title.ToLower().Trim() == dto.Title.ToLower().Trim() && q.ParentId == dto.ParentId);

            if (exist != null)
            {
                return(Exceptions.getDuplicateException("Option-01", "Title"));
            }


            return(new CustomActionResult(HttpStatusCode.OK, ""));
        }