public VersionSurveyEntity Update(UserEntity userEntity, Guid VersionSurveyId,
                                          VersionSurveyEntity VersionSurveyEntity)
        {
            if (VersionSurveyEntity.Content.Equals(String.Empty) ||
                VersionSurveyEntity.Content == null ||
                VersionSurveyEntity.Version == 0)
            {
                throw new BadRequestException("Field khong duoc trong");
            }
            if (!VersionSurveyValidator(VersionSurveyId))
            {
                throw new BadRequestException("Cannot Update Version Survey Content");
            }

            VersionSurvey
                VersionSurvey = context.VersionSurveys.FirstOrDefault(c => c.Id == VersionSurveyId); //add include later

            if (VersionSurvey == null)
            {
                throw new NotFoundException("VersionSurvey Not Found");
            }
            VersionSurvey updateVersionSurvey = new VersionSurvey(VersionSurveyEntity);
            DateTime?     createdDate         = VersionSurvey.CreatedDate;

            updateVersionSurvey.CopyTo(VersionSurvey);
            VersionSurvey.ModifiedDate = DateTime.Now;
            VersionSurvey.CreatedDate  = createdDate;
            context.SaveChanges();
            return(new VersionSurveyEntity(VersionSurvey));
        }
Exemplo n.º 2
0
        public VersionSurveyEntity Update(UserEntity userEntity, Guid VersionSurveyId, VersionSurveyEntity VersionSurveyEntity)
        {
            if (VersionSurveyEntity.Content.Equals(String.Empty) ||
                VersionSurveyEntity.Content == null ||
                VersionSurveyEntity.Version.ToString() == null)
            {
                throw new BadRequestException("Field must not empty!");
            }
            VersionSurvey VersionSurvey = context.VersionSurveys.FirstOrDefault(c => c.Id == VersionSurveyId);

            if (VersionSurvey == null)
            {
                throw new NotFoundException("VersionSurvey not found!");
            }
            VersionSurvey updateVersionSurvey = new VersionSurvey(VersionSurveyEntity);
            DateTime?     createdDate         = VersionSurvey.CreatedDate;

            updateVersionSurvey.CopyTo(VersionSurvey);
            VersionSurvey.ModifiedDate = DateTime.Now;
            VersionSurvey.CreatedDate  = createdDate;
            context.SaveChanges();
            return(new VersionSurveyEntity(VersionSurvey));
        }