Beispiel #1
0
        public static Form MapModelToForm(FormModel model)
        {
            Form form = new Form()
            {
                ClubId = model.ClubId,
                CreatedByUserId = model.CreatedByUserId,
                CreatedDate = model.CreatedDate,
                EndDate = model.EndDate.ToUniversalTime() <= DateTime.MinValue ? DateTime.Now.AddDays(-1) : model.EndDate.ToUniversalTime(),
                Id = model.Id,
                IsDeleted = model.IsDeleted,
                IsExternal = model.IsExternal,
                Name = model.Name,
                StartDate = model.StartDate.ToUniversalTime() <= DateTime.MinValue ? DateTime.Now.AddDays(-1) : model.StartDate.ToUniversalTime(),
                Description = model.Description ?? string.Empty,
                MultipleSubmits = model.MultipleSubmits,
                SendThanksMail = model.SendThanksMail,
                EmailFieldName = model.EmailFieldName ?? string.Empty,
                EmailHtml = model.EmailHtml ?? string.Empty,
                EnableExcelImport = model.EnableExcelImport,
                ExampleExcelPath = model.ExampleExcelPath ?? string.Empty
            };

            foreach (var item in model.FormFields)
            {
                FormFields field = new Gradera.Forms.DAL.FormFields()
                {
                    ClassName = item.ClassName,
                    FormId = form.Id,
                    Id = item.Id,
                    IsRequired = item.IsRequired,
                    Label = item.Label,
                    Type = item.Type,
                    CanMultiply = item.CanMultiply
                };

                item.Options.ForEach(o => field.FormFieldsOptions.Add(new FormFieldsOptions()
                {
                    FormFieldId = field.Id,
                    GroupName = o.GroupName,
                    Id = o.Id,
                    Name = o.Name
                }));

                form.FormFields.Add(field);
            }

            foreach (var email in model.Emails)
            {
                form.Form_Emails.Add(new Form_Emails()
                {
                    Email = email.Email,
                    FormId = form.Id,
                    Id = email.Id
                });
            }

            return form;
        }
Beispiel #2
0
        public HttpResponseMessage SaveForm(FormModel form)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
            UserPrincipal loggedInUser = (UserPrincipal)HttpContext.Current.User;
            form.ClubId = loggedInUser.AccountSession.ClubId;
            if (form.Id <= 0)
            {
                form.CreatedByUserId = loggedInUser.AccountSession.AccountId;
                form.CreatedDate = DateTime.Now;
            }

            Gradera.Forms.DAL.Form f = FormModel.MapModelToForm(form);
            FormsAdminBLL.SaveForm(f);
            return response;
        }
Beispiel #3
0
        public static FormModel MapFormModel(Form form, bool deepLoad = false)
        {
            FormModel model = new FormModel()
            {
                ClubId = form.ClubId,
                CreatedByUserId = form.CreatedByUserId,
                CreatedDate = form.CreatedDate,
                EndDate = form.EndDate,
                Id = form.Id,
                IsDeleted = form.IsDeleted,
                IsExternal = form.IsExternal,
                Name = form.Name,
                StartDate = form.StartDate,
                Description = form.Description,
                MultipleSubmits = form.MultipleSubmits,
                SendThanksMail = form.SendThanksMail,
                EmailFieldName = form.EmailFieldName,
                EmailHtml = form.EmailHtml,
                EnableExcelImport = form.EnableExcelImport,
                ExampleExcelPath = form.ExampleExcelPath
            };

            if(deepLoad)
            {
                form.FormFields.ToList().ForEach(f => model.FormFields.Add(FormFieldModel.MapFormFieldModel(f)));
                form.Form_Emails.ToList().ForEach(e => model.Emails.Add(new FormEmailModel()
                {
                    Email = e.Email,
                    Id = e.Id,
                    FormId = e.FormId
                }));
            }

            return model;
        }