public void FillFieldsFromViewModel(WebForm webFormToUpdate, WebFormFieldEditAdminViewModel[] webFormFields)
 {
     this.WebForm = webFormToUpdate;
     this.WebFormFields = webFormToUpdate.WebFormFields;
     this.webFormFieldPostData = webFormFields;
     this._webFormFieldViewModels = null;
 }
Example #2
0
        public static WebFormField UpdateWebFormField(this IGstoreDb db, WebFormFieldEditAdminViewModel viewModel, StoreFront storeFront, UserProfile userProfile)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }

            if (viewModel.WebFormId == 0)
            {
                throw new ArgumentNullException("viewModel.WebFormId", "viewModel.WebFormId cannot be 0. Make sure it's set in the form");
            }

            if (viewModel.WebFormFieldId == 0)
            {
                throw new ArgumentNullException("viewModel.WebFormFieldId", "viewModel.WebFormFieldId cannot be 0. Make sure it's set in the form");
            }

            if (storeFront == null)
            {
                throw new ArgumentNullException("storeFront");
            }
            if (userProfile == null)
            {
                throw new ArgumentNullException("userProfile");
            }

            //find existing record, update it
            WebFormField webFormFieldToUpdate = db.WebFormFields.Where(wf => wf.ClientId == storeFront.ClientId && (wf.WebFormId == viewModel.WebFormId) && (wf.WebFormFieldId == viewModel.WebFormFieldId)).SingleOrDefault();
            if (webFormFieldToUpdate == null)
            {
                throw new ApplicationException("Web Form Field not found in client web form fields. Web Form Field Id: " + viewModel.WebFormFieldId + " Web Form Id: " + viewModel.WebFormId + " Client '" + storeFront.Client.Name + " [" + storeFront.ClientId + "]");
            }

            webFormFieldToUpdate.DataType = viewModel.DataType;
            webFormFieldToUpdate.DataTypeString = viewModel.DataType.ToDisplayName();
            webFormFieldToUpdate.Description = viewModel.Description;
            webFormFieldToUpdate.EndDateTimeUtc = viewModel.EndDateTimeUtc;
            webFormFieldToUpdate.HelpLabelBottomText = viewModel.HelpLabelBottomText;
            webFormFieldToUpdate.HelpLabelTopText = viewModel.HelpLabelTopText;
            webFormFieldToUpdate.IsPending = viewModel.IsPending;
            webFormFieldToUpdate.IsRequired = viewModel.IsRequired;
            webFormFieldToUpdate.LabelText = viewModel.LabelText;
            webFormFieldToUpdate.Watermark = viewModel.Watermark;
            webFormFieldToUpdate.Name = viewModel.Name;
            webFormFieldToUpdate.Order = viewModel.Order;
            webFormFieldToUpdate.StartDateTimeUtc = viewModel.StartDateTimeUtc;
            webFormFieldToUpdate.TextAreaColumns = viewModel.TextAreaColumns;
            webFormFieldToUpdate.TextAreaRows = viewModel.TextAreaRows;
            webFormFieldToUpdate.UpdateDateTimeUtc = DateTime.UtcNow;
            webFormFieldToUpdate.UpdatedBy = userProfile;
            webFormFieldToUpdate.UpdatedBy_UserProfileId = userProfile.UserProfileId;
            webFormFieldToUpdate.ValueListId = viewModel.ValueListId;

            webFormFieldToUpdate.UpdateAuditFields(userProfile);
            try
            {
                webFormFieldToUpdate = db.WebFormFields.Update(webFormFieldToUpdate);
                db.SaveChanges();
                return webFormFieldToUpdate;
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Database update failed", ex);
            }
        }