Esempio n. 1
0
        /// <summary>
        ///     Method returns filtered Employees from databse
        /// </summary>
        /// <param name="filter">Name or Surname or PersonalIdentityNumber of Employee</param>
        /// <returns>Collection of Employees from Database</returns>
        public async Task <ObservableCollection <DtoEmployee> > GetEmployees(string filter = null)
        {
            var ret = new ObservableCollection <DtoEmployee>();

            using (var data = Context)
                if (!string.IsNullOrWhiteSpace(filter))
                {
                    foreach (var item in await(from item in data.Employee
                                               where
                                               item.name.Contains(filter) || item.surname.Contains(filter) ||
                                               item.personalIdentityNumber.Contains(filter)
                                               select item).ToListAsync())
                    {
                        ret.Add(EmployeeConverter.DataAccsessToDto(item));
                    }
                }
                else
                {
                    foreach (var item in await(from item in data.Employee select item).ToListAsync())
                    {
                        ret.Add(EmployeeConverter.DataAccsessToDto(item));
                    }
                }
            return(ret);
        }
Esempio n. 2
0
 /// <summary>
 ///     Returns Employee with specific ID
 /// </summary>
 /// <param name="employeeId">Employee ID</param>
 /// <returns>Employee Business Object</returns>
 public async Task <DtoEmployee> GetEmployee(int employeeId)
 {
     try
     {
         using (var data = Context)
             return
                 (EmployeeConverter.DataAccsessToDto(
                      await
                          (from item in data.Employee where item.id == employeeId select item)
                      .FirstOrDefaultAsync()));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 3
0
        /// <summary>
        ///     Returns Employee with specific email
        /// </summary>
        /// <param name="email">Employee e-mail</param>
        /// <returns>Employee Business Object</returns>
        public async Task <DtoEmployee> GetEmployee(string email)
        {
            using (var data = Context)
            {
                var emps = await data.Employee.Where(e => e.email == email).ToListAsync();

                if (!emps.Any())
                {
                    return(null);
                }
                if (emps.Count > 1)
                {
                    throw new Exception("Emails are not unique");
                }
                return(EmployeeConverter.DataAccsessToDto(emps.First()));
            }
        }