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));
        }
示例#2
0
        public VersionSurveyEntity Get(UserEntity userEntity, Guid VersionSurveyId)
        {
            VersionSurvey VersionSurvey = context.VersionSurveys.FirstOrDefault(c => c.Id == VersionSurveyId);

            if (VersionSurvey == null)
            {
                throw new NotFoundException("VersionSurvey not found!");
            }
            return(new VersionSurveyEntity(VersionSurvey));
        }
        public VersionSurveyEntity(VersionSurvey versionSurvey, params object[] args) : base(versionSurvey)
        {
            if (!String.IsNullOrEmpty(this.Content))
            {
                ContentCategory = JsonConvert.DeserializeObject <Dictionary <string, string> >(this.Content);
            }

            foreach (var arg in args)
            {
                if (arg is ICollection <Form> forms)
                {
                    this.Forms = forms.Select(s => new FormEntity(s)).ToList();
                }
            }
        }
        public VersionSurveyEntity Create(UserEntity userEntity, VersionSurveyEntity versionSurveyEntity)
        {
            if (versionSurveyEntity.Content.Equals(String.Empty) ||
                versionSurveyEntity.Content == null ||
                versionSurveyEntity.Version == 0)
            {
                throw new BadRequestException("Field khong duoc trong");
            }
            VersionSurvey versionSurvey = new VersionSurvey(versionSurveyEntity);

            versionSurvey.Id          = Guid.NewGuid();
            versionSurvey.CreatedDate = DateTime.Now;
            context.VersionSurveys.Add(versionSurvey);
            context.SaveChanges();
            return(new VersionSurveyEntity(versionSurvey));
        }
示例#5
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));
        }