示例#1
0
        public async Task <IHttpActionResult> PostUserCertification(ViewModels.PersonCertificationDto 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;

            PersonCertification entity = null;

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

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

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

            //ViewModels.Location.Fill(entity, dto);
            ViewModels.PersonCertificationDto.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(PersonCertification entity)
 {
     this.context.PersonCertifications.Remove(entity);
 }