Example #1
0
        public static bool Add(EmployeesViewModel model)
        {
            bool result = false;

            using (EmplDataContext db = new EmplDataContext())
            {
                MST_Employees mstEmployee = new MST_Employees();
                mstEmployee.FirstName     = model.FirstName;
                mstEmployee.LastName      = model.LastName;
                mstEmployee.Gender        = model.Gender;
                mstEmployee.JobPositionId = model.JobPositionId;
                mstEmployee.UserId        = model.UserId;
                mstEmployee.Password      = model.Password;
                mstEmployee.isActive      = model.isActive;

                try
                {
                    db.MST_Employees.Add(mstEmployee);
                    db.SaveChanges();
                    result = true;
                }
                catch
                {
                    result = false;
                }
            }
            return(result);
        }
Example #2
0
        public static bool Update(EmployeesViewModel model)
        {
            bool result = false;

            using (EmplDataContext db = new EmplDataContext())
            {
                MST_Employees mstEmployee = db.MST_Employees.Where(x => x.Id == model.Id).FirstOrDefault();
                mstEmployee.FirstName     = model.FirstName;
                mstEmployee.LastName      = model.LastName;
                mstEmployee.Gender        = model.Gender;
                mstEmployee.JobPositionId = model.JobPositionId;
                mstEmployee.UserId        = model.UserId;
                mstEmployee.Password      = model.Password;
                mstEmployee.isActive      = model.isActive;
                mstEmployee.ModifiedBy    = 1;
                mstEmployee.ModifiedOn    = DateTime.Now;

                try
                {
                    db.SaveChanges();
                    result = true;
                }
                catch
                {
                    result = false;
                }
            }
            return(result);
        }
Example #3
0
        public static bool Delete(int id)
        {
            bool result = false;

            using (EmplDataContext db = new EmplDataContext())
            {
                MST_Employees mstEmployee = db.MST_Employees.Where(x => x.Id == id).FirstOrDefault();
                try
                {
                    db.MST_Employees.Remove(mstEmployee);
                    db.SaveChanges();
                    result = true;
                }
                catch
                {
                    result = false;
                }
            }
            return(result);
        }