Пример #1
0
        public BugTrackingResponse <BusinessObjects.AspNetRole> Save(BusinessObjects.AspNetRole role)
        {
            Logger.TraceMethodStart(ClassName, "Save");

            var response = new BugTrackingResponse <BusinessObjects.AspNetRole>();


            using (var db = new EntityModel.BugTrackingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var validator = new RoleSpecification();
                        var result    = validator.Validate(role);
                        var failures  = result.Errors;

                        response.ValidationResult = result;

                        if (result.IsValid)
                        {
                            role.Id           = Guid.NewGuid().ToString();
                            role.LastModified = DateTime.Now;
                            role.Active       = true;
                            var newrole = MapperAllLevels.Map <BusinessObjects.AspNetRole, EntityModel.AspNetRole>(role);
                            db.AspNetRoles.Add(newrole);
                            db.SaveChanges();
                            transaction.Commit();
                        }

                        else
                        {
                            transaction.Rollback();
                            Logger.TraceErrorFormat("Error while Saving {0}", response.ValidationResult.Errors);
                        }

                        return(response);
                    }

                    catch (Exception ex)
                    {
                        Logger.TraceError("Exception: ", ex);
                        transaction.Rollback();
                        throw;
                    }

                    finally
                    {
                        Logger.TraceMethodEnd(ClassName, "Save");
                    }
                }
            }
        }
        public ActionResult CreateRole([Bind(Include = "Id,Name,Description,Active,LastModified")] BusinessObjects.AspNetRole role)
        {
            var response = this.rolemanager.Save(role);

            if (!response.IsError)
            {
                return(RedirectToAction("/RoleList"));
            }

            else
            {
                foreach (var failer in response.ValidationResult.Errors)
                {
                    ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage);
                }
                return(View());
            }
        }