Exemplo n.º 1
0
        public virtual ActionResult Index(EmployeePortalViewModel ob, FormCollection form)
        {
            ob.Pages = _repo.GetAll().Where(x => x.ParentId == null && x.Status == VersionableItemStatus.Live).ToList();


            try
            {
                var obj = ob.Item;

                _settingsRepo.Add(obj, 1);

                obj.Password = IMCMS.Common.Hashing.AESEncrypt.Encrypt(obj.Password);

                if (ModelState.IsValid)
                {
                    _settingsRepo.Edit(entity: obj, BaseID: 1);
                    _uow.Commit();
                    ModifiedItem();
                }
            }
            catch (Exception ex)
            {
                RaiseError(ex);
            }

            ViewBag.History = _settingsRepo.GetVersions(1).ToList();

            return(View(ob));
        }
Exemplo n.º 2
0
        /// <summary>
        /// method that acutally saves from Edit and Create
        /// </summary>
        /// <param name="id">Base ID of object being saved. Null if new</param>
        /// <param name="ob">Object to be saved</param>
        /// <param name="form">Form collection</param>
        /// <returns>Action Result to be passed back to the user</returns>
        private ActionResult Save(int?id, T ob, FormCollection form)
        {
            try
            {
                using (var scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    _repo.Add(ob, id);

                    OnSaving(ob, form, id.HasValue ? EditingType.Edit : EditingType.Insert);


                    if (ModelState.IsValid)
                    {
                        var slug = GenerateSlug(ob);
                        if (slug.IsNotNullOrEmpty())
                        {
                            ob.Slug = slug;
                        }


                        if (id.HasValue)
                        {
                            _repo.Edit(entity: ob, BaseID: id.Value);
                        }
                        //else
                        //_repo.Add(ob);

                        _uow.Commit();

                        OnSaved(ob, form);
                        _uow.Commit();


                        var actionResult = OnSaveFinished(SaveResult.Success, ob);

                        if (id.HasValue)
                        {
                            ModifiedItem();
                        }
                        else
                        {
                            CreatedItem();
                        }

                        scope.Complete();

                        return(actionResult);
                    }
                    else
                    {
                        OnEditRendering(ob);
                        return(OnSaveFinished(SaveResult.Fail, ob));
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var validationError in ex.EntityValidationErrors.SelectMany(validationErrors => validationErrors.ValidationErrors))
                {
                    RaiseError(String.Format("Property: {0} Error: {1}\n", validationError.PropertyName, validationError.ErrorMessage));
                }

                RaiseError(ex);

                OnEditRendering(ob);
                return(OnSaveFinished(SaveResult.Fail, ob));
            }
            catch (Exception ex)
            {
                RaiseError(ex);
                OnEditRendering(ob);
                return(OnSaveFinished(SaveResult.Fail, ob));
            }
        }