public void CreateForm(Form formDto) { Validate(formDto); var form = new Entities.Form.Form { User = _h5FormsContext.Users.Single(u => string.Equals(u.UserName, formDto.User.UserName)), CreateDate = DateTime.Now, UpdateDate = DateTime.Now, Enabled = formDto.Enabled, Title = formDto.Title, LabelLayoutType = (int)formDto.LabelLayoutType, Controls = Mapper.Map<Form, Entities.Form.Form>(formDto).Controls }; using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions() {IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted})){ #region Form _h5FormsContext.Forms.Add(form); _h5FormsContext.SaveChanges(); form.Hash = HashHelper.Hash(string.Format("{0}{1}{2}", form.Id, formDto.User.UserName, form.CreateDate)).Replace("/", string.Empty).Replace("+", string.Empty).Replace("=", string.Empty); _h5FormsContext.SaveChanges(); #endregion #region FormEntryModel var columns = formDto.Controls.Where(c => c is ValueControl).Select(c => c.ColumnName).ToList(); _h5FormsContext.CreateEntryModel(form.Id, columns); #endregion transaction.Complete(); } }
public ActionResult CreateForm(Form form) { var response = new Response<int> { Result = new Result() { HasErrors = false, Messages = new List<string>() } }; try { form.User = new User { UserName = User.Identity.GetUserName() }; _formAdmin.CreateForm(form); } catch (ValidationException exception) { response.Result.HasErrors = true; response.Result.Messages.Add(exception.Message); } catch (Exception) { response.Result.HasErrors = true; response.Result.Messages.Add(Resource.GeneralError); } return this.JsonNet(response); }
public ActionResult UpdateForm(Form form) { var response = new Response<int> { Result = new Result() { HasErrors = false, Messages = new List<string>() } }; try { _formAdmin.UpdateForm(form); } catch (ValidationException exception) { response.Result.HasErrors = true; response.Result.Messages.Add(exception.Message); } catch (Exception) { response.Result.HasErrors = true; response.Result.Messages.Add(Resource.GeneralError); } return this.JsonNet(response); }
private void Validate(Form formDto) { if(formDto.Controls == null || !formDto.Controls.Any(c => c is ValueControl)) throw new ValidationException(Resource.ControlsEmpty); }
private Dictionary<string, string> GeEntryFormated(Form formDto, Entities.Form.FormEntry entry) { var result = new Dictionary<string, string>(); result["EntryDate"] = entry.EntryDate.ToString(); result["Ip"] = entry.Ip; var entryDto = Mapper.Map<Entities.Form.FormEntry, FormEntry>(entry); formDto.SetValues(entryDto); foreach (var kv in entry.ControlValues) { var controlId = int.Parse(kv.Key.Replace(FormSettings.COLUMN_PREFIX, string.Empty)); var control = formDto.Controls.Single(c => c.Id == controlId) as ValueControl; result[kv.Key] = control.GetFormattedValue(); //var optionValues = kv.Value; //if (control is OptionsControl) //{ // var optionsControl = (control as OptionsControl); // switch (control.ControlType) // { // case ControlType.OptionList: // { // var values = optionValues.Split(new[] {FormSettings.SELECTED_VALUES_SEPARATOR}).ToArray(); // if (!string.IsNullOrEmpty(values[0])) // { // var option = optionsControl.Options.SingleOrDefault(o => o.Id == int.Parse(values[0])); // if (option != null) // values[0] = option.Value; // } // optionValues = string.Join(FormSettings.SELECTED_VALUES_CLIENT_SEPARATOR.ToString(), values.Where(v => !string.IsNullOrEmpty(v))); // } // break; // default: // { // var optionIds = optionValues.Split(new[] {FormSettings.SELECTED_VALUES_SEPARATOR}).Where(id => !string.IsNullOrEmpty(id)).Select(id => int.Parse(id)).ToArray(); // optionValues = string.Join(FormSettings.SELECTED_VALUES_CLIENT_SEPARATOR.ToString(), optionsControl.Options.Where(o => optionIds.Any(oi => oi == o.Id)).Select(o => o.Value).ToArray()); // } // break; // } //} } return result; }
public void UpdateForm(Form formDto) { Validate(formDto); var form = _h5FormsContext.Forms.Single(f => f.Id == formDto.Id); form.Title = formDto.Title; form.UpdateDate = DateTime.Now; form.Enabled = formDto.Enabled; form.LabelLayoutType = (int)formDto.LabelLayoutType; form.Controls = Mapper.Map<Form, Entities.Form.Form>(formDto).Controls; var columns = formDto.Controls.Where(c => c is ValueControl).Select(c => c.ColumnName).ToList(); _h5FormsContext.UpdateEntryModel(form.Id, columns); _h5FormsContext.SaveChanges(); }