示例#1
0
        public BugTrackingResponse <BusinessObjects.Status> Save(BusinessObjects.Status stat)
        {
            Logger.TraceMethodStart(ClassName, "Save");

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


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

                        response.ValidationResult = result;

                        if (result.IsValid)
                        {
                            stat.Active       = true;
                            stat.LastModified = DateTime.Now;
                            var newstat = MapperAllLevels.Map <BusinessObjects.Status, EntityModel.Status>(stat);
                            db.Status.Add(newstat);
                            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 CreateStatus([Bind(Include = "ID,Name,Description,Active,LastModified")] BusinessObjects.Status stat)
        {
            var response = statusmanager.Save(stat);

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

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