示例#1
0
        public async Task <IHttpActionResult> PostJobGroup(ViewModels.JobGroup dto)
        {
            // return Ok(client);
            if (dto == null)
            {
                return(Exceptions.getNullException(ModelState));
            }
            if (!ModelState.IsValid)
            {
                // return BadRequest(ModelState);
                return(Exceptions.getModelValidationException(ModelState));
            }
            var validate = unitOfWork.JobgroupRepository.Validate(dto);

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

            JobGroup entity      = null;
            var      oldFullCode = string.Empty;

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

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

                oldFullCode = entity.FullCode;
            }

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

            //ViewModels.Location.Fill(entity, dto);
            ViewModels.JobGroup.Fill(entity, dto);

            if (dto.Id != -1 && entity.FullCode != oldFullCode)
            {
                unitOfWork.JobgroupRepository.UpdateChildren(entity, entity.FullCode);
            }

            var saveResult = await unitOfWork.SaveAsync();

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

            dto.Id = entity.Id;
            return(Ok(dto));
        }
示例#2
0
 public static void FillDto(Models.JobGroup entity, ViewModels.JobGroup jobgroup)
 {
     jobgroup.Id         = entity.Id;
     jobgroup.ParentId   = entity.ParentId;
     jobgroup.Title      = entity.Title;
     jobgroup.Code       = entity.Code;
     jobgroup.FullCode   = entity.FullCode;
     jobgroup.Remark     = entity.Remark;
     jobgroup.CustomerId = entity.CustomerId;
 }
        public virtual CustomActionResult Validate(ViewModels.JobGroup dto)
        {
            var exist = dbSet.FirstOrDefault(q => q.Id != dto.Id && q.CustomerId == dto.CustomerId && q.Title.ToLower().Trim() == dto.Title.ToLower().Trim());

            if (exist != null)
            {
                return(Exceptions.getDuplicateException("JobGroup-01", "Title"));
            }
            var fullcode = dbSet.FirstOrDefault(q => q.Id != dto.Id && q.CustomerId == dto.CustomerId && q.FullCode == dto.FullCode);

            if (fullcode != null)
            {
                return(Exceptions.getDuplicateException("JobGroup-02", "FullCode"));
            }

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