Esempio n. 1
0
        public ActionResult Edit(FormViewModel vm)
        {
            var model = GetModel();

            if (ModelState.IsValid)
            {
                FormContainer formContainer = model.Region <FormContainer>("FormContainer");
                CFItem        submission    = SubmissionService.SaveSubmission(
                    vm.Form,
                    vm.FormSubmissionRef,
                    vm.ItemId,
                    formContainer.EntityTypeId,
                    formContainer.FormId,
                    formContainer.CollectionId);

                CFAuditEntry.eAction action = submission.Id == 0 ? CFAuditEntry.eAction.Create : CFAuditEntry.eAction.Update;
                string actor = User.Identity.IsAuthenticated ? User.Identity.Name : "Annonymous";
                Db.SaveChanges(User.Identity);

                string confirmLink = "confirmation";
                return(Redirect(confirmLink));
            }

            ViewBag.PageModel = model;
            return(View(model.GetView(), vm));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an audit entry and adds the change log into it.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="actor"></param>
        /// <param name="timestamp"></param>
        /// <returns></returns>
        public CFAuditEntry FlushChangeLog(CFAuditEntry.eAction action, string actor, DateTime?timestamp = null)
        {
            CFAuditEntry entry = new CFAuditEntry(action, actor, timestamp.HasValue ? timestamp.Value : DateTime.Now, mChangeLog);

            AddAuditEntry(entry);
            mChangeLog.Clear();
            return(entry);
        }
Esempio n. 3
0
        public JsonResult Submit(FormViewModel vm, FormContainer formContainer)
        {
            if (ModelState.IsValid)
            {
                SubmissionService subSrv = new SubmissionService(Db);
                //add AttributeMappings -- Apr 10 2018
                IDictionary <string, string> attributeMappings = new Dictionary <string, string>();
                foreach (var map in formContainer.FieldMappings)
                {
                    attributeMappings.Add(map.AttributeName, map.FieldName);
                }
                CFItem submission = subSrv.SaveSubmission(
                    vm.Form,
                    vm.FormSubmissionRef,
                    vm.ItemId,
                    formContainer.EntityTypeId,
                    formContainer.FormId,
                    formContainer.CollectionId, attributeMappings);

                //Sept 16 2019 -- if formContainer.AttachItemToUser = true, throw exception if current user is not authenticate
                if (formContainer.AttachItemToUser)
                {
                    if (!User.Identity.IsAuthenticated)
                    {
                        //throw new HttpException("You have to authenticate to save this page.");
                        vm.Errors = new Dictionary <string, string[]>();
                        vm.Errors.Add("NotAuthorized", (new string[] { "You are not authorized." }));
                        return(Json(vm));
                    }
                }


                // Set's the audit log value when saving.
                // TODO: this should be more automated.
                CFAuditEntry.eAction action = submission.Id == 0 ? CFAuditEntry.eAction.Create : CFAuditEntry.eAction.Update;
                string actor = User.Identity.IsAuthenticated ? User.Identity.Name : "Annonymous";



                Db.SaveChanges(User.Identity);
            }
            else
            {
                vm.Errors = new Dictionary <string, string[]>();

                IEnumerable <KeyValuePair <string, System.Web.Mvc.ModelState> > errors = ModelState.Where(m => m.Value.Errors.Count > 0);
                List <string> errorList = new List <string>();
                foreach (var error in errors)
                {
                    vm.Errors.Add(error.Key, error.Value.Errors.Select(e => e.ErrorMessage).ToArray());
                    // errorList.AddRange(error.Value.Errors.Select(e => e.ErrorMessage));
                }

                // vm.Errors.Add("Message", errorList.ToArray());
            }

            return(Json(vm));
        }
Esempio n. 4
0
        public int SaveChanges(string actor)
        {
            if (this.ChangeTracker.HasChanges())
            {
                foreach (var entry in this.ChangeTracker.Entries <CFXmlModel>())
                {
                    if (entry.State != EntityState.Unchanged && entry.State != EntityState.Deleted)
                    {
                        CFAuditEntry.eAction action = entry.Entity.Id == 0 ? CFAuditEntry.eAction.Create : CFAuditEntry.eAction.Update;
                        entry.Entity.FlushChangeLog(action, actor);
                        entry.Entity.Serialize();
                    }
                }
            }

            return(base.SaveChanges());
        }
Esempio n. 5
0
        public JsonResult Submit(FormViewModel vm, FormContainer formContainer)
        {
            if (ModelState.IsValid)
            {
                SubmissionService subSrv = new SubmissionService(Db);
                //add AttributeMappings -- Apr 10 2018
                IDictionary <string, string> attributeMappings = new Dictionary <string, string>();
                foreach (var map in formContainer.FieldMappings)
                {
                    attributeMappings.Add(map.AttributeName, map.FieldName);
                }
                CFItem submission = subSrv.SaveSubmission(
                    vm.Form,
                    vm.FormSubmissionRef,
                    vm.ItemId,
                    formContainer.EntityTypeId,
                    formContainer.FormId,
                    formContainer.CollectionId, attributeMappings);

                // Set's the audit log value when saving.
                // TODO: this should be more automated.
                CFAuditEntry.eAction action = submission.Id == 0 ? CFAuditEntry.eAction.Create : CFAuditEntry.eAction.Update;
                string actor = User.Identity.IsAuthenticated ? User.Identity.Name : "Annonymous";
                Db.SaveChanges(User.Identity);
            }
            else
            {
                vm.Errors = new Dictionary <string, string[]>();

                IEnumerable <KeyValuePair <string, System.Web.Mvc.ModelState> > errors = ModelState.Where(m => m.Value.Errors.Count > 0);
                foreach (var error in errors)
                {
                    vm.Errors.Add(error.Key, error.Value.Errors.Select(e => e.ErrorMessage).ToArray());
                }
            }

            return(Json(vm));
        }