public void SaveUserRole(BusinessObjects.AspNetUserRole UserRole)
        {
            Logger.TraceMethodStart(ClassName, "Save");



            using (var db = new EntityModel.BugTrackingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        UserRole.LastModified = DateTime.Now;
                        UserRole.Active       = true;
                        var newUserRole = MapperAllLevels.Map <BusinessObjects.AspNetUserRole, EntityModel.AspNetUserRole>(UserRole);
                        db.AspNetUserRoles.Add(newUserRole);
                        db.SaveChanges();
                        transaction.Commit();
                    }

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

                    finally
                    {
                        Logger.TraceMethodEnd(ClassName, "Save");
                    }
                }
            }
        }
        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");
                    }
                }
            }
        }
        public BugTrackingResponse <BusinessObjects.ProductOrganisation> DeleteOrganizationConfirmed(int Id)
        {
            Logger.TraceMethodStart(ClassName, "DeleteOrganizationConfirmed");

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


            using (var db = new EntityModel.BugTrackingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var query   = db.ProductOrganisations.Where(c => c.ID == Id && c.Active == true).FirstOrDefault();
                        var prodorg = MapperAllLevels.Map <EntityModel.ProductOrganisation, BusinessObjects.ProductOrganisation>(query);

                        var validator = new ProdOrganizationDeleteSpecification();
                        var result    = validator.Validate(prodorg);
                        var failures  = result.Errors;

                        response.ValidationResult = result;

                        if (result.IsValid)
                        {
                            //db.ProductOrganisations.Remove(query);
                            query.Active       = false;
                            query.LastModified = DateTime.Now;
                            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, "DeleteOrganizationConfirmed");
                    }
                }
            }
        }
示例#4
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 BugTrackingResponse <BusinessObjects.ProductOrganisation> SaveProductOrganisation(BusinessObjects.ProductOrganisation productorganisation)
        {
            Logger.TraceMethodStart(ClassName, "SaveProductOrganisation");

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

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

                        response.ValidationResult = result;

                        if (result.IsValid)
                        {
                            productorganisation.Active       = true;
                            productorganisation.LastModified = DateTime.Now;
                            var productorg = MapperAllLevels.Map <BusinessObjects.ProductOrganisation, EntityModel.ProductOrganisation>(productorganisation);
                            db.ProductOrganisations.Add(productorg);
                            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, "SaveProductOrganisation");
                    }
                }
            }
        }
示例#6
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");
                    }
                }
            }
        }
        public void DeleteUserConfirmed(int Id)
        {
            Logger.TraceMethodStart(ClassName, "DeleteUserConfirmed");



            using (var db = new EntityModel.BugTrackingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var query = db.Users.Where(c => c.ID == Id && c.Active == true)
                                    .Include(x => x.AspNetUser)
                                    .FirstOrDefault();

                        var user = MapperAllLevels.Map <EntityModel.User, BusinessObjects.User>(query);
                        //db.Users.Remove(query);
                        query.Active            = false;
                        query.LastModified      = DateTime.Now;
                        query.AspNetUser.Active = false;

                        db.SaveChanges();

                        transaction.Commit();
                    }

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

                    finally
                    {
                        Logger.TraceMethodEnd(ClassName, "DeleteUserConfirmed");
                    }
                }
            }
        }
        public void ActivateExistingUser(int Id)
        {
            Logger.TraceMethodStart(ClassName, "ActivateUser");



            using (var db = new EntityModel.BugTrackingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var query = db.Users.Where(c => c.ID == Id && c.Active == false)
                                    .Include(x => x.AspNetUser)
                                    .SingleOrDefault()
                        ;

                        query.Active            = true;
                        query.AspNetUser.Active = true;

                        // var user = MapperAllLevels.Map<EntityModel.User, BusinessObjects.User>(query);

                        //db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                        transaction.Commit();
                    }

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

                    finally
                    {
                        Logger.TraceMethodEnd(ClassName, "SaveAddInfo");
                    }
                }
            }
        }
        public BugTrackingResponse <BusinessObjects.RegisterViewModel> SaveUser(BusinessObjects.RegisterViewModel Register)
        {
            Logger.TraceMethodStart(ClassName, "SaveUser");
            var response = new BugTrackingResponse <BusinessObjects.RegisterViewModel>();


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

                        response.ValidationResult = result;

                        if (result.IsValid)
                        {
                            var usernamedata = db.AspNetUsers.Where(c => c.UserName == Register.Email && c.Active == true).SingleOrDefault();
                            var user         = MapperAllLevels.Map <BusinessObjects.RegisterViewModel, EntityModel.User>(Register);


                            user.Active          = true;
                            user.LastModified    = DateTime.Now;
                            user.UserId          = usernamedata.Id;
                            user.Email           = usernamedata.Email;
                            user.Username        = usernamedata.UserName;
                            user.FirstName       = Register.FirstName;
                            user.LastName        = Register.LastName;
                            user.OrganizationID  = Register.OrganizationID;
                            user.TelephoneNumber = Register.TelephoneNumber;

                            var userrole = MapperAllLevels.Map <BusinessObjects.RegisterViewModel, EntityModel.AspNetUserRole>(Register);
                            userrole.RoleId       = Register.RoleId;
                            userrole.UserId       = usernamedata.Id;
                            userrole.Active       = true;
                            userrole.LastModified = DateTime.Now;

                            db.AspNetUserRoles.Add(userrole);
                            db.Users.Add(user);

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