public Employee addEmployee(string idCard, string locationName, string name, long location, string account, double salary, long avalaibleVacations, string CMS = null) { Employee result = null; try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { EmployeeEntity employee = new EmployeeEntity() { idCard = idCard, location=locationName,cms = CMS, name = name, locationId = location, active = true, account = account, salary=salary,workedDays=0, negativeAmount=0, avalaibleVacations=avalaibleVacations}; var x = repository.Employees.Add(employee); repository.Complete(); result = new Employee() { id = x.id, idCard = x.idCard, name = x.name, location = x.locationId, locationName = x.location, account = x.account, cmsText = CMS, salary = x.salary, active = x.active, avalaibleVacations = x.avalaibleVacations, activeSince = DateTime.Now }; } } catch (Exception e) { throw validateException(e); } return result; }
public Location addLocation(string name, double call_price, long administrator, long workingDaysPerMonth, long workingHoursPerDay) { Location result = null; try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { LocationEntity location = new LocationEntity() { name = name, callPrice = call_price, active = true , isPendingToApprove= false, workingDaysPerMonth=workingDaysPerMonth,workingHoursPerDay=workingHoursPerDay}; location = repository.Locations.Add(location); repository.Complete(); updateAdministrator(location.id, administrator); result = new Location(); result.Name = location.name; result.CallPrice = location.callPrice; result.LastPayroll = location.lastPayrollId; result.CurrentPayroll = location.currentPayrollId; result.Active = location.active; result.isPendingToApprove = location.isPendingToApprove; } } catch (Exception e) { throw validateException(e); } return result; }
public AmortizationDebit addAmortizationDebit(long employee, string Detail, double total, long pays, long type, long period) { AmortizationDebit result = null; try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var debit = repository.Debits.Add(new DebitEntity() { initialDate = DateTime.Today, description = Detail, employeeId = employee, totalAmount = total, remainingAmount = total, paysMade = 0, remainingPays = pays, debitTypeId = type, active = true, period = period, activeSince = DateTime.Today }); repository.Complete(); result = (AmortizationDebit)toModel(debit); } } catch (Exception e) { throw validateException(e); } return result; }
public void assignPenaltiesToPayroll(long payrollId,long location, DateTime endDate) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { repository.Penalties.assignPayroll(payrollId,location, endDate); repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public void addOperationGroup(string name, string description, string icon) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { GroupEntity group = new GroupEntity() { Name = name, Description = description, Icon = icon }; repository.Groups.Add(group); repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public void addOperation(string name, string description, string url, string group, bool isPayrollCalculationRelated) { Result<string> result = new Result<string>(); try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { OperationEntity operation = new OperationEntity() { Name = name, Description = description, GroupId = group , isPayrollCalculationRelated=isPayrollCalculationRelated}; repository.Operations.Add(operation); repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public void assignSalaryToPayroll(long employee,long payroll,double grossSalary, double netSalary) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { repository.Salaries.Add(new SalaryEntity() { employeeId=employee, payrollId=payroll, salary=grossSalary, netSalary=netSalary }); repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public void addCall(String cms, long calls, TimeSpan hours, DateTime date) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var employee = repository.Employees.selectEmployeeByCmsText(cms); if (employee != null) { var call = repository.Calls.callByEmployeeDate(employee.id, date); if (call != null) { call.calls = calls; call.time = hours; } else { repository.Calls.Add(new CallEntity() { employeeId = employee.id, calls = calls, time = hours, date = date, payrollId = null }); } repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentEmployee); } } } catch (Exception e) { throw validateException(e); } }
public void activateRole(long id) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { RoleEntity role = repository.Roles.Get(id); if (role != null) { role.active = true; repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentRole); } } } catch (Exception e) { throw validateException(e); } }
public void activateUser(long id) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var user = repository.Users.Get(id); if (user != null) { user.active = true; } else { throw validateException(App_LocalResoures.Errors.inexistentUser); } var rows = repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public void deleteExtra(long idExtra) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var extra = repository.Extras.Get(idExtra); if (extra != null) { repository.Extras.Remove(extra); } else { throw validateException(App_LocalResoures.Errors.inexistentExtra); } var rows = repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
private void deleteOperation(string id) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { OperationEntity operation = repository.Operations.Get(id); if (operation != null) { repository.Operations.Remove(operation); repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentGroup); } } } catch (Exception e) { throw validateException(e); } }
public void deletePenalty(long idRecess) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { PenaltyEntity penalty = repository.Penalties.Get(idRecess); if (penalty != null) { repository.Penalties.Remove(penalty); repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentEmployee); } } } catch (Exception e) { throw validateException(e); } }
public Penalty addPenalty(long employee, string Detail, long amount, long months, long penaltyTypeId, DateTime date) { Penalty result = null; try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var penalty = new PenaltyEntity() { Amount = amount, Date = date, Description = Detail, EmployeeId = employee, PenaltyTypeId = penaltyTypeId, PenaltyPrice = repository.PenaltyTypes.getPriceById(penaltyTypeId), }; penalty = repository.Penalties.Add(penalty); repository.Complete(); result = new Penalty() { id = penalty.Id, amount = penalty.Amount, date = penalty.Date, detail = penalty.Description, employee = penalty.EmployeeId, type = penalty.PenaltyTypeId, typeName = penalty.fkpenalty_type.name, penaltyPrice =penalty.PenaltyPrice }; } } catch (Exception e) { throw validateException(e); } return result; }
public User addUser(string name, string username, string password, long role, long location, string email) { User user = null; try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var u = repository.Users.Add(new UserEntity() { name = name, email = email, locationId = location, password = BCryptHelper.HashPassword(password, BCryptHelper.GenerateSalt()), roleId = role, userName = username.ToLower(), active = true }); repository.Complete(); user = new User() { Id = u.id, Name = u.name, Username = u.userName, Role = u.roleId, Email = u.email, Location = u.locationId, Active = u.active }; } } catch (Exception e) { throw validateException(e); } return user; }
public void deleteLocation(long id) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { LocationEntity location = repository.Locations.Get(id); if (location != null && location.active) { location.active = false; repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentLocation); } } } catch (Exception e) { throw validateException(e); } }
public Role addRole(string name, long location, List<string> operations) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { RoleEntity role = repository.Roles.Add(new RoleEntity() { name = name, locationId = location, active = true }); foreach (var op in operations) { OperationEntity operation = repository.Operations.Get(op); if (operation != null) { repository.RoleOperations.Add(new RoleOperationEntity() { role= role.id,operation=operation.Name}); } } repository.Complete(); List<Tuple<string, string, bool>> list = new List<Tuple<string, string, bool>>(); var roleOperations = repository.RoleOperations.getOperationsByRole(role.id); foreach (var op in roleOperations) { var operation = repository.Operations.Get(op.operation); Tuple<string, string, bool> tuple = new Tuple<string, string, bool>(operation.GroupId, operation.Name.Split('/')[1], operation.isPayrollCalculationRelated); list.Add(tuple); } return new Role(role.id, role.name, role.locationId, role.active, list); } } catch (Exception e) { throw validateException(e); } return null; }
public Extra addExtra(long employee, string Detail, long hours) { Extra result = null; try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var extra = new ExtraEntity() { employeeId = employee, description = Detail, hours = hours }; extra = repository.Extras.Add(extra); var rows = repository.Complete(); result = new Extra() { employee = extra.employeeId, detail = extra.description, hours = extra.hours, id = extra.id }; } } catch (Exception e) { throw validateException(e); } return result; }
public void activateEmployee(long employeeId) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { EmployeeEntity employee = repository.Employees.Get(employeeId); if (employee != null) { employee.active = true; employee.activeSince = DateTime.Now; repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentEmployee); } } } catch (Exception e) { throw validateException(e); } }
public void activateDebit(long idDebit) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { DebitEntity debit = repository.Debits.Get(idDebit); if (debit != null) { debit.active = true; debit.activeSince = DateTime.Today; repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentDebit); } } } catch (Exception e) { throw validateException(e); } }
public void updatePassword(long id, string password) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var user = repository.Users.Get(id); if (user != null) { password = BCryptHelper.HashPassword(password, BCryptHelper.GenerateSalt()); } else { throw validateException(App_LocalResoures.Errors.inexistentEmployee); } repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public void updatePenalty(long idRecess, long payroll, long penaltyTypeId, string Detail, long amount, DateTime date) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var penalty = repository.Penalties.Get(idRecess); if (penalty != null) { penalty.payrollId = payroll; penalty.Description = Detail; penalty.PenaltyTypeId = penaltyTypeId; penalty.Amount = amount; penalty.PenaltyPrice = repository.PenaltyTypes.getPriceById(penaltyTypeId); penalty.Date = date; } else { throw validateException(App_LocalResoures.Errors.inexistentExtra); } var rows = repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public Dictionary<long, PenaltyType> selectAllPenaltyTypes(long location) { Dictionary<long, PenaltyType> result = new Dictionary<long, PenaltyType>(); try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var types = repository.PenaltyTypes.getAllbyLocation(location); foreach (var p in types) { result.Add(p.Id, new PenaltyType() { id = p.Id, name = p.name, price = p.price }); } repository.Complete(); } } catch (Exception e) { throw validateException(e); } return result; }
public void updateExtra(long idExtra, string Detail, long hours) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var extra = repository.Extras.Get(idExtra); if (extra != null) { extra.hours = (long)hours; extra.description = Detail; } else { throw validateException(App_LocalResoures.Errors.inexistentExtra); } var rows = repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public void updateLocationLastPayroll(long id) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { LocationEntity location = repository.Locations.Get(id); if (location != null) { location.lastPayrollId = location.currentPayrollId; location.currentPayrollId = null; location.isPendingToApprove = false; repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentLocation); } } } catch (Exception e) { throw validateException(e); } }
public void updateLocationCurrentPayroll(long id, Nullable<long> current_payroll) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { LocationEntity location = repository.Locations.Get(id); if (location != null) { if (location.currentPayrollId != null) { var current = repository.PayRolls.Get((long)location.currentPayrollId); repository.PayRolls.Remove(current); } location.currentPayrollId = current_payroll; repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentLocation); } } } catch (Exception e) { throw validateException(e); } }
public void updateLocation(long id, string name, double call_price) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { LocationEntity location = repository.Locations.Get(id); if (location != null) { location.name = name; location.callPrice = call_price; repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentLocation); } } } catch (Exception e) { throw validateException(e); } }
public void updateAdministrator(long location, long administrator) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { AdministratorEntity admin = repository.Administrators.Get(location); if (admin != null) { admin.user_id = administrator; } else { repository.Administrators.Add(new AdministratorEntity() { location = location, user_id = administrator }); } repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public void updateUser(long id, string name, string username, long role, long location, string email) { try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { var user = repository.Users.Get(id); if (user != null) { user.name = name; user.userName = username; user.roleId = role; user.locationId = location; user.email = email; } else { throw validateException(App_LocalResoures.Errors.inexistentEmployee); } repository.Complete(); } } catch (Exception e) { throw validateException(e); } }
public void deleteRole(long id) { Result<string> result = new Result<string>(); try { using (var repository = new MainRepository(new AppContext("PostgresConnection"))) { RoleEntity role = repository.Roles.Get(id); if (role != null) { //var Users = selectAllActiveUsers(role.locationId); List<User> userResult = new List<User>(); var users = repository.Users.GetAll(); foreach (UserEntity ue in users) { if (ue.active == true) { userResult.Add(new User() { Id = ue.id, Email = ue.email, Location = ue.locationId, Name = ue.name, Password = ue.password, Role = ue.roleId, Username = ue.userName, Active = true }); } } if (userResult.TrueForAll(u => u.Role != role.id)) role.active = false; else throw validateException(App_LocalResoures.Errors.roleWithUser); repository.Complete(); } else { throw validateException(App_LocalResoures.Errors.inexistentRole); } } } catch (Exception e) { throw validateException(e); } }