/// <summary> /// Metodo para cargar los menus disponibles para un administrador /// </summary> /// <returns>void</returns> public static void procUploadPermissionsToMenuByAdministrator() { bool isExistente = false; isExistente = Database.Exists(dbCtx.Database.Connection); if (isExistente) { var result = dbCtx.Permissions.ToList().Count > 0; if (!result) { dbCtx.Database.ExecuteSqlCommand("INSERT INTO Permission (RoleId, ModuleId) SELECT 1, Id FROM Module;"); dbCtx.SaveChanges(); } } }
/// <summary> /// Metodo para registrar los empleados para trabajar con el /// Viper Sistema de Punto de Venta para Farmacias /// </summary> /// <param name="loginID">Nombre de Usuario (C.U.R.P.)</param> /// <param name="pwdEncrypted">Contraseña Encriptada con SHA1</param> /// <param name="roleID">Tipo de Usuario</param> /// <param name="entityAddress">Entidad de Direccion del Empleado</param> /// <param name="entityEmployee">Entidad de Empleado</param> /// <param name="entityEDH">Entidad del Historial del Empleado</param> /// <returns>Message</returns> public static string procInsertEmployeeToSystem(string loginID, string pwdEncrypted, int roleID, Address entityAddress, Employee entityEmployee, EmployeeDepartmentHistory entityEDH) { String message = String.Empty; bool isInserted = false; using (var dbCtxTran = dbCtx.Database.BeginTransaction()) { try { bool isDataBaseExist = Database.Exists(dbCtx.Database.Connection); if (isDataBaseExist) { User user = new User() { LoginID = loginID, PasswordEncrypted = pwdEncrypted, RoleId = roleID, AccessFailedCount = 0, IsWelcome = true, IsActive = true, CreatedBy = "HECP", CreatedDate = DateTime.Now, LastUpdatedBy = "HECP", LastUpdatedDate = DateTime.Now }; dbCtx.Users.Add(user); isInserted = dbCtx.SaveChanges() > 0; if (isInserted) { dbCtx.Addresses.Add(entityAddress); isInserted = dbCtx.SaveChanges() > 0; if (isInserted) { int AddressID = dbCtx.Addresses.OrderByDescending(x => x.Id).FirstOrDefault().Id; if (AddressID > 0) { int UserID = dbCtx.Users.Where(x => x.LoginID == loginID).OrderByDescending(x => x.Id).FirstOrDefault().Id; entityEmployee.EmployeeNumber = procObtainEmployeeNumberGeneratedAutomatic(); entityEmployee.UserId = UserID; entityEmployee.AddressId = AddressID; dbCtx.Employees.Add(entityEmployee); isInserted = dbCtx.SaveChanges() > 0; if (isInserted) { int EmployeeID = dbCtx.Employees.Where(x => x.CURP == entityEmployee.CURP).OrderByDescending(x => x.Id).FirstOrDefault().Id; entityEDH.EmployeeId = EmployeeID; dbCtx.EmployeesDepartmentHistory.Add(entityEDH); isInserted = dbCtx.SaveChanges() > 0; if (isInserted) { dbCtxTran.Commit(); } } } } } } } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); message = exceptionMessage + "\n" + ex.EntityValidationErrors; dbCtxTran.Rollback(); } catch (DbUpdateConcurrencyException ex) { var entityObj = ex.Entries.Single().GetDatabaseValues(); if (entityObj == null) { message = "The entity being updated is already deleted by another user"; } else { message = "The entity being updated has already been updated by another user"; } dbCtxTran.Rollback(); } catch (DbUpdateException ex) { var exception = HandleDbUpdateException(ex); message = exception.Message; dbCtxTran.Rollback(); } catch (Exception ex) { message = ex.Message; dbCtxTran.Rollback(); } } return(message); }
/// <summary> /// Metodo para registrar los productos para vender con el /// Viper Sistema de Punto de Venta para Farmacias /// </summary> /// <param name="entityProduct">Entidad Producto</param> /// <param name="SiteID">ID Sucursal</param> /// <param name="UnitsInStock">Unidades en Stock</param> /// <returns></returns> public static string procInsertProductToSystem(Product entityProduct, int SiteID, int UnitsInStock) { String message = String.Empty; bool isInserted = false; using (var dbCtxTran = dbCtx.Database.BeginTransaction()) { try { bool isDataBaseExist = Database.Exists(dbCtx.Database.Connection); if (isDataBaseExist) { dbCtx.Products.Add(entityProduct); isInserted = dbCtx.SaveChanges() > 0; if (isInserted) { int ProductID = dbCtx.Products.Where(x => x.BarCode == entityProduct.BarCode).OrderByDescending(x => x.Id).FirstOrDefault().Id; ProductCostHistory productCostHistory = new ProductCostHistory() { ProductId = ProductID, SiteId = SiteID, StantardCost = entityProduct.StandardCost, StartDate = DateTime.Now }; dbCtx.ProductsCostHistory.Add(productCostHistory); isInserted = dbCtx.SaveChanges() > 0; if (isInserted) { ProductListPriceHistory productListPriceHistory = new ProductListPriceHistory() { ProductId = ProductID, SiteId = SiteID, ListPrice = entityProduct.ListPrice, StartDate = DateTime.Now }; dbCtx.ProductsListPriceHistory.Add(productListPriceHistory); isInserted = dbCtx.SaveChanges() > 0; if (isInserted) { ProductInventory productInventory = new ProductInventory() { ProductId = ProductID, UnitsInStock = UnitsInStock, SiteId = SiteID, }; dbCtx.ProductsInventory.Add(productInventory); isInserted = dbCtx.SaveChanges() > 0; if (isInserted == true) { dbCtxTran.Commit(); } } } } } } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); message = exceptionMessage + "\n" + ex.EntityValidationErrors; dbCtxTran.Rollback(); } catch (DbUpdateConcurrencyException ex) { var entityObj = ex.Entries.Single().GetDatabaseValues(); if (entityObj == null) { message = "The entity being updated is already deleted by another user"; } else { message = "The entity being updated has already been updated by another user"; } dbCtxTran.Rollback(); } catch (DbUpdateException ex) { var exception = HandleDbUpdateException(ex); message = exception.Message; dbCtxTran.Rollback(); } catch (Exception ex) { message = ex.Message; dbCtxTran.Rollback(); } } return(message); }
/// <summary> /// Metodo para registrar un usuario con valores default, dentro del sistema viper /// </summary> /// <param name="loginID">Nombre de usuario</param> /// <param name="passwordEncrypted">Contraseña encriptada</param> /// <param name="RoleID">ID identificador del rol para asignar</param> /// <returns>Message</returns> public static string procInsertUserToSystem(string loginID, string passwordEncrypted, int RoleID) { String message = String.Empty; bool isInserted = false; using (var dbCtxTran = dbCtx.Database.BeginTransaction()) { try { bool isDataBaseExist = Database.Exists(dbCtx.Database.Connection); if (isDataBaseExist) { User user = new User() { LoginID = loginID, PasswordEncrypted = passwordEncrypted, RoleId = RoleID, AccessFailedCount = 0, IsWelcome = true, IsActive = true, CreatedBy = "HECP", CreatedDate = DateTime.Now, LastUpdatedBy = "HECP", LastUpdatedDate = DateTime.Now }; dbCtx.Users.Add(user); isInserted = dbCtx.SaveChanges() > 0; if (isInserted) { dbCtxTran.Commit(); } } } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); message = exceptionMessage + "\n" + ex.EntityValidationErrors; dbCtxTran.Rollback(); } catch (DbUpdateConcurrencyException ex) { var entityObj = ex.Entries.Single().GetDatabaseValues(); if (entityObj == null) { message = "The entity being updated is already deleted by another user"; } else { message = "The entity being updated has already been updated by another user"; } dbCtxTran.Rollback(); } catch (DbUpdateException ex) { var exception = HandleDbUpdateException(ex); message = exception.Message; dbCtxTran.Rollback(); } } return(message); }
/// <summary> /// Metodo para registrar los datos de las sucursales que tiene ligadas la empresa /// que adquirio la licencia del sistema viper /// </summary> /// <param name="entity">Entidad Sucursal</param> /// <returns>Message</returns> public static string procInsertSiteToSystem(Site entity) { String message = String.Empty; bool isInserted = false; using (var dbCtxTran = dbCtx.Database.BeginTransaction()) { try { bool isDataBaseExist = Database.Exists(dbCtx.Database.Connection); if (isDataBaseExist) { dbCtx.Sites.Add(entity); isInserted = dbCtx.SaveChanges() > 0; if (isInserted) { dbCtxTran.Commit(); } } } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); message = exceptionMessage + "\n" + ex.EntityValidationErrors; dbCtxTran.Rollback(); } catch (DbUpdateConcurrencyException ex) { var entityObj = ex.Entries.Single().GetDatabaseValues(); if (entityObj == null) { message = "The entity being updated is already deleted by another user"; } else { message = "The entity being updated has already been updated by another user"; } dbCtxTran.Rollback(); } catch (DbUpdateException ex) { var exception = HandleDbUpdateException(ex); message = exception.Message; dbCtxTran.Rollback(); } } return(message); }