Exemple #1
0
 /// <summary>
 /// To save new Employee
 /// </summary>
 /// <param name="employee">Employee Details of new Employee.</param>
 /// <returns>It returns true if Employee successfully added.</returns>
 public ResultStatus SaveEmployee(LicenseManagementMVC.BusinessEntities.Employee employee)
 {
     try
     {
         using (LicenseManagementMVCEntities salesDal = new LicenseManagementMVCEntities()){
             Data.Model.Employee emp = new Data.Model.Employee()
             {
                 FirstName   = employee.FirstName,
                 LastName    = employee.LastName,
                 Email       = employee.Email,
                 Password    = new LoginBusinessLayer().EncodePassword(employee.Password),
                 LocationId  = employee.LocationId,
                 RoleId      = employee.RoleId,
                 IsReleased  = false,
                 ReleaseDate = null,
                 JoiningDate = employee.JoiningDate ?? DateTime.Now
             };
             if (new LicenseManagementMVCEntities().Employees.Any(o => o.Email == emp.Email))
             {
                 return(ResultStatus.AlreadyExist);
             }
             salesDal.Employees.Add(emp);
             salesDal.SaveChanges();
             return(ResultStatus.Success);
         }
     }catch (Exception exp) {
         //TODO
         return(ResultStatus.ConnectionError);
     }
 }
Exemple #2
0
        /// <summary>
        /// This method will add new employee to database
        /// </summary>
        /// <param name="objEmp">Object holding all the details of new employee</param>
        /// <returns>Returns ResultStatus enum which reflect the status of operation performed</returns>
        public ResultStatus SaveAddRecord(EmployeeVm objEmp)
        {
            try
            {
                using (Data.Model.LicenseManagementMVCEntities DbContext = new LicenseManagementMVCEntities())
                {
                    try
                    {
                        Data.Model.Employee employee = new Data.Model.Employee();

                        if (objEmp != null)
                        {
                            employee.FirstName   = objEmp.FirstName;
                            employee.LastName    = objEmp.LastName;
                            employee.Email       = objEmp.Email;
                            employee.RoleId      = objEmp.RoleId;
                            employee.LocationId  = objEmp.LocationId;
                            employee.JoiningDate = objEmp.JoiningDate;
                            employee.ReleaseDate = objEmp.ReleaseDate;
                            employee.IsReleased  = objEmp.IsReleased;
                            BusinessLayer.LoginBusinessLayer objLogin = new LoginBusinessLayer();
                            employee.Password = objLogin.EncodePassword("mindfire");

                            DbContext.Employees.Add(employee);
                            int result = DbContext.SaveChanges();
                            if (result < 1)
                            {
                                return(ResultStatus.QueryNotExecuted);
                            }
                        }
                        else
                        {
                            return(ResultStatus.QueryNotExecuted);
                        }
                    }
                    catch (Exception)
                    {
                        return(ResultStatus.QueryNotExecuted);
                    }
                }
            }
            catch (Exception)
            {
                return(ResultStatus.ConnectionError);
            }
            return(ResultStatus.Success);
        }