Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public Vacation addVacation(long employeeId,DateTime date, double price)
 {
     try
     {
         using (var repository = new MainRepository(new AppContext("PostgresConnection")))
         {
            var vacation= repository.Vacations.Add(new VacationEntity()
             {
                 employeeId=employeeId,
                 date=date,
                 vacationsPrice=price
             });
             return new Vacation()
             {
                 employee = vacation.employeeId,
                 date = vacation.date,
                 vacationPrice = vacation.vacationsPrice
             };
         }
     }
     catch (Exception e)
     {
         throw validateException(e);
     }
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 public Extra selectExtra(long idExtra)
 {
     Extra result = null;
     try
     {
         using (var repository = new MainRepository(new AppContext("PostgresConnection")))
         {
             var extra = repository.Extras.Get(idExtra);
             if (extra != null)
             {
                 result = new Extra()
                 {
                     hours = extra.hours,
                     detail = extra.description,
                     employee = extra.employeeId,
                     id = extra.id
                 };
             }
             else
             {
                 throw validateException(App_LocalResoures.Errors.inexistentExtra);
             }
         }
     }
     catch (Exception e)
     {
         throw validateException(e);
     }
     return result;
 }
Esempio n. 5
0
        public void addAmortizationDebitType(string name, long location, long pays, double interestRate, long period)
        {
            try
            {
                using (var repository = new MainRepository(new AppContext("PostgresConnection")))
                {
                    if (interestRate == 0)
                        throw validateException(App_LocalResoures.Errors.zeroInterestRate);
                    repository.DebitTypes.Add(new DebitTypeEntity()
                    {
                        name = name,
                        locationId = location,
                        pays = pays,
                        interestRate = interestRate,
                        type = "A",
                        period=period
                    });

                    repository.Complete();
                }
            }
            catch (Exception e)
            {
                throw validateException(e);
            }
        }
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 8
0
 public double selectSavingByEmployee(long employee)
 {
     try
     {
         using (var repository = new MainRepository(new AppContext("PostgresConnection")))
         {
             var saving = repository.Savings.Get(employee);
             return saving != null ? saving.amount : 0;
         }
     }
     catch (Exception e)
     {
         throw validateException(e);
     }
 }
Esempio n. 9
0
 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);
     }
 }
Esempio n. 10
0
 public List<Salary> getLastSalaries(long employeeId)
 {
     try
     {
         using (var repository = new MainRepository(new AppContext("PostgresConnection")))
         {
             var salaries= repository.Salaries.selectLastSalariesByEmployee(employeeId);
             return salaries.Select(s => new Salary()
             { payroll = s.payrollId, employee = s.employeeId, salary = s.salary, netSalary = s.netSalary, workedDays = s.workedDays }).ToList();
         }
     }
     catch (Exception e)
     {
         throw validateException(e);
     }
 }
Esempio n. 11
0
 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);
     }
 }
Esempio n. 12
0
 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);
     }
 }
Esempio n. 13
0
 public List<Operation> selectAllOperationByGroup(String id_group)
 {
     List<Operation> result = new List<Operation>();
     try
     {
         using (var repository = new MainRepository(new AppContext("PostgresConnection")))
         {
             var os = repository.Operations.selectOperationsByGroup(id_group);
             foreach (var x in os)
                 result.Add(new Operation(x.Name, x.Name.Split('/')[1], x.GroupId, x.Description,x.isPayrollCalculationRelated));
         }
     }
     catch (Exception e)
     {
         throw validateException(e);
     }
     return result;
 }
Esempio n. 14
0
 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);
     }
 }
Esempio n. 15
0
 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);
     }
 }
Esempio n. 16
0
 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);
     }
 }
Esempio n. 17
0
 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);
     }
 }
Esempio n. 18
0
 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);
     }
 }
Esempio n. 19
0
 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);
     }
 }
Esempio n. 20
0
 public void deleteUser(long id)
 {
     try
     {
         using (var repository = new MainRepository(new AppContext("PostgresConnection")))
         {
             var user = repository.Users.Get(id);
             if (user != null)
             {
                 user.active = false;
             }
             else
             {
                 throw validateException(App_LocalResoures.Errors.inexistentUser);
             }
             var rows = repository.Complete();
         }
     }
     catch (Exception e)
     {
         throw validateException(e);
     }
 }
Esempio n. 21
0
 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;
 }
Esempio n. 22
0
        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);
            }
        }
Esempio n. 23
0
 public List<OperationsGroup> selectAllOperationsGroup()
 {
     List<OperationsGroup> result = new List<OperationsGroup>();
     try
     {
         using (var repository = new MainRepository(new AppContext("PostgresConnection")))
         {
             var os = repository.Groups.GetAll();
             foreach (var x in os)
             {
                 var operations = repository.Operations.selectOperationsByGroup(x.Name);
                 List<Operation> list = new List<Operation>();
                 foreach (var op in operations)
                     list.Add(new Operation(op.Name, op.Name.Split('/')[1], op.GroupId, op.Description,op.isPayrollCalculationRelated));
                 result.Add(new OperationsGroup(x.Description, x.Name, x.Icon, list));
             }
         }
     }
     catch (Exception e)
     {
         throw validateException(e);
     }
     return result;
 }
Esempio n. 24
0
 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);
     }
 }
Esempio n. 25
0
 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;
 }
Esempio n. 26
0
 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;
 }
Esempio n. 27
0
        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;
        }
Esempio n. 28
0
 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);
     }
 }
Esempio n. 29
0
 private Operation getOperation(string id)
 {
     Operation result = null;
     try
     {
         using (var repository = new MainRepository(new AppContext("PostgresConnection")))
         {
             var x = repository.Operations.Get(id);
             if (x != null)
             {
                 result = new Operation(x.Name, x.Name.Split('/')[1], x.GroupId, x.Description,x.isPayrollCalculationRelated);
             }
             else
             {
                 throw validateException(App_LocalResoures.Errors.inexistentGroup);
             }
         }
     }
     catch (Exception e)
     {
         throw validateException(e);
     }
     return result;
 }
Esempio n. 30
0
 public List<Penalty> selectAllPenalty(long employee, DateTime endDate)
 {
     List<Penalty> result = new List<Penalty>();
     try
     {
         using (var repository = new MainRepository(new AppContext("PostgresConnection")))
         {
             var penalties = repository.Penalties.selectPenaltiesByEmployee(employee, endDate);
             foreach (var p in penalties)
             {
                 result.Add(new Penalty()
                 {
                     id = p.Id,
                     amount = (double)p.Amount,
                     date = p.Date,
                     detail = p.Description,
                     employee = p.EmployeeId,
                     type = p.PenaltyTypeId,
                     typeName = p.fkpenalty_type.name,
                     penaltyPrice = p.PenaltyPrice
                 });
             }
         }
     }
     catch (Exception e)
     {
         throw validateException(e);
     }
     return result;
 }