internal static void SaveFormFieldItem(FormFields formField) { using (FormsEntities formDAL = new FormsEntities()) { if (formField.Id <= 0) { formDAL.Entry(formField).State = System.Data.Entity.EntityState.Added; } else { foreach (var option in formField.FormFieldsOptions) { if (option.Id <= 0) { formDAL.Entry(option).State = System.Data.Entity.EntityState.Added; } else { formDAL.Entry(option).State = System.Data.Entity.EntityState.Modified; } } formDAL.Entry(formField).State = System.Data.Entity.EntityState.Modified; } formDAL.SaveChanges(); } }
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 SW.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); }
internal static void DeleteFormFieldItem(int formFieldId, int clubId) { using (FormsEntities formDAL = new FormsEntities()) { FormFields field = formDAL.FormFields.Include("Form").FirstOrDefault(f => f.Id == formFieldId && f.Form.ClubId == clubId); if (field != null) { formDAL.Entry(field).State = System.Data.Entity.EntityState.Deleted; formDAL.SaveChanges(); } } }