Beispiel #1
0
 public static void FillDto(Models.PersonAward entity, ViewModels.PersonAwardDto personaward)
 {
     personaward.Id       = entity.Id;
     personaward.Title    = entity.Title;
     personaward.Date     = entity.Date;
     personaward.Issuer   = entity.Issuer;
     personaward.Remark   = entity.Remark;
     personaward.PersonId = entity.PersonId;
 }
Beispiel #2
0
 public static void Fill(Models.PersonAward entity, ViewModels.PersonAwardDto personaward)
 {
     entity.Id       = personaward.Id;
     entity.Title    = personaward.Title;
     entity.Date     = personaward.Date;
     entity.Issuer   = personaward.Issuer;
     entity.Remark   = personaward.Remark;
     entity.PersonId = personaward.PersonId;
 }
Beispiel #3
0
        public async Task <IHttpActionResult> PostUserAward(ViewModels.PersonAwardDto dto)
        {
            // return Ok(client);
            if (dto == null)
            {
                return(Exceptions.getNullException(ModelState));
            }
            if (!ModelState.IsValid)
            {
                // return BadRequest(ModelState);
                return(Exceptions.getModelValidationException(ModelState));
            }
            // var validate = unitOfWork.PersonMiscRepository.Validate(dto);
            // if (validate.Code != HttpStatusCode.OK)
            //      return validate;

            PersonAward entity = null;

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

            else
            {
                entity = await unitOfWork.PersonRepository.GetAwardByID(dto.Id);
            }

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

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



            var saveResult = await unitOfWork.SaveAsync();

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

            dto.Id = entity.Id;
            return(Ok(dto));
        }
Beispiel #4
0
        public async Task <IHttpActionResult> DeleteUserAward(ViewModels.PersonAwardDto dto)
        {
            var entity = await unitOfWork.PersonRepository.GetAwardByID(dto.Id);

            if (entity == null)
            {
                return(NotFound());
            }
            //var canDelete = unitOfWork.PersonRepository.CanDelete(entity);
            //if (canDelete.Code != HttpStatusCode.OK)
            //    return canDelete;

            unitOfWork.PersonRepository.Delete(entity);

            var saveResult = await unitOfWork.SaveAsync();

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

            return(Ok(dto));
        }