예제 #1
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));
        }
예제 #2
0
        public async Task <CustomActionResult> SaveAccompolishments(ViewModels.AccomplishmentDto dto)
        {
            var publication = await this.context.PersonPublications.FirstOrDefaultAsync(q => q.PersonId == dto.Id);

            var patent = await this.context.PersonPatents.FirstOrDefaultAsync(q => q.PersonId == dto.Id);

            var project = await this.context.PersonProjects.FirstOrDefaultAsync(q => q.PersonId == dto.Id);

            var certification = await this.context.PersonCertifications.FirstOrDefaultAsync(q => q.PersonId == dto.Id);

            var award = await this.context.PersonAwards.FirstOrDefaultAsync(q => q.PersonId == dto.Id);

            if (string.IsNullOrEmpty(dto.Publication.Title) && publication != null)
            {
                this.context.PersonPublications.Remove(publication);
            }
            else
            {
                if (publication == null)
                {
                    publication = new PersonPublication()
                    {
                        PersonId = dto.Id
                    };
                    this.context.PersonPublications.Add(publication);
                }
                publication.Publisher = dto.Publication.Publisher;
                publication.Remark    = dto.Publication.Remark;
                publication.Title     = dto.Publication.Title;
                publication.Date      = dto.Publication.Date;
            }

            if (string.IsNullOrEmpty(dto.Patent.Title) && patent != null)
            {
                this.context.PersonPatents.Remove(patent);
            }
            else
            {
                if (patent == null)
                {
                    patent = new PersonPatent()
                    {
                        PersonId = dto.Id
                    };
                    this.context.PersonPatents.Add(patent);
                }
                patent.Title  = dto.Patent.Title;
                patent.Date   = dto.Patent.Date;
                patent.Remark = dto.Patent.Remark;
                patent.Issuer = dto.Patent.Issuer;
            }

            if (string.IsNullOrEmpty(dto.Project.Title) && project != null)
            {
                this.context.PersonProjects.Remove(project);
            }
            else
            {
                if (project == null)
                {
                    project = new PersonProject()
                    {
                        PersonId = dto.Id
                    };
                    this.context.PersonProjects.Add(project);
                }
                project.Title  = dto.Project.Title;
                project.Remark = dto.Project.Remark;
                project.Date   = dto.Project.Date;
            }

            if (string.IsNullOrEmpty(dto.Certification.Title) && certification != null)
            {
                this.context.PersonCertifications.Remove(certification);
            }
            else
            {
                if (certification == null)
                {
                    certification = new PersonCertification()
                    {
                        PersonId = dto.Id
                    };
                    this.context.PersonCertifications.Add(certification);
                }
                certification.Remark    = dto.Certification.Remark;
                certification.Title     = dto.Certification.Title;
                certification.Authority = dto.Certification.Authority;
            }

            if (string.IsNullOrEmpty(dto.Award.Title) && award != null)
            {
                this.context.PersonAwards.Remove(award);
            }
            else
            {
                if (award == null)
                {
                    award = new PersonAward()
                    {
                        PersonId = dto.Id
                    };
                    this.context.PersonAwards.Add(award);
                }
                award.Date   = dto.Award.Date;
                award.Issuer = dto.Award.Issuer;
                award.Remark = dto.Award.Remark;
                award.Title  = dto.Award.Title;
            }

            return(new CustomActionResult(HttpStatusCode.OK, true));
        }
예제 #3
0
 public virtual void Delete(PersonAward entity)
 {
     this.context.PersonAwards.Remove(entity);
 }