Ejemplo n.º 1
0
        public void SaveEditUser(BusinessObjects.User User)
        {
            Logger.TraceMethodStart(ClassName, "SaveEditUser");



            using (var db = new EntityModel.BugTrackingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        User.LastModified = DateTime.Now;
                        var resp = MapperAllLevels.Map <BusinessObjects.User, EntityModel.User>(User);
                        db.Entry(resp).State = EntityState.Modified;
                        db.SaveChanges();
                        transaction.Commit();
                    }

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

                    finally
                    {
                        Logger.TraceMethodEnd(ClassName, "SaveEditUser");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public BugTrackingResponse <BusinessObjects.Category> SaveEdit(BusinessObjects.Category category)
        {
            Logger.TraceMethodStart(ClassName, "SaveEdit");

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

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

                        response.ValidationResult = result;

                        if (result.IsValid)
                        {
                            category.LastModified = DateTime.Now;
                            var newcat = MapperAllLevels.Map <BusinessObjects.Category, EntityModel.Category>(category);
                            db.Entry(newcat).State = EntityState.Modified;

                            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, "SaveEdit");
                    }
                }
            }
        }