Esempio n. 1
0
        public ActionResult Department(FormCollection collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    DepartmentMaster d  = new DepartmentMaster();
                    bool             ok = TryUpdateModel(d, collection);
                    using (PracticalTestEntities pt = new PracticalTestEntities())
                    {
                        if (d.DepartmentId == 0)
                        {
                            pt.DepartmentMasters.Add(d);
                        }
                        else
                        {
                            pt.Entry(d).State = EntityState.Modified;
                        }

                        pt.SaveChanges();
                    }
                }
                return(RedirectToAction("Department", new { id = 0 }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
 public ActionResult Add(FormCollection collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var  employee = new Employee();
             bool ok       = TryUpdateModel(employee, collection);
             using (PracticalTestEntities pt = new PracticalTestEntities())
             {
                 if (employee.EmployeeId == 0)
                 {
                     pt.Employees.Add(employee);
                 }
                 else
                 {
                     pt.Entry(employee).State = EntityState.Modified;
                 }
                 pt.SaveChanges();
             }
         }
         return(RedirectToAction("List"));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 3
0
 private List <EmployeeModel> GetEmployee(int id = 0)
 {
     try
     {
         using (PracticalTestEntities pt = new PracticalTestEntities())
         {
             var Data = pt.Employees.Where(x => id > 0 ? x.EmployeeId == id : true).Select(x => new EmployeeModel()
             {
                 EmployeeId     = x.EmployeeId,
                 Name           = x.Name,
                 Address        = x.Address,
                 Surname        = x.Surname,
                 Qualification  = x.Qualification,
                 DepartmentList = (from ed in pt.EmployeeDepartments
                                   join d in pt.DepartmentMasters on ed.DepartmentId equals d.DepartmentId
                                   where id > 0 ? ed.EmployeeId == id : true
                                   select new Department()
                 {
                     Name = d.DepartmentName,
                     DepartmentId = d.DepartmentId
                 }).ToList()
             });
             return(Data.ToList());
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Esempio n. 4
0
 public static SelectList DepartmentList()
 {
     using (PracticalTestEntities pt = new PracticalTestEntities())
     {
         return(new SelectList(pt.DepartmentMasters.ToList(), "DepartmentId", "DepartmentName"));
     }
 }
Esempio n. 5
0
 public List <UserViewModel> GetAll()
 {
     using (PracticalTestEntities _context = new PracticalTestEntities())
     {
         var _RetObj = new List <UserViewModel>();
         _RetObj = _context.tbl_usermaster.Where(x => x.IsActive == true).AsEnumerable().Select(t => t.ToModel()).ToList();
         return(_RetObj);
     }
 }
Esempio n. 6
0
 public UserViewModel GetUserbyID(string Id)
 {
     using (PracticalTestEntities _context = new PracticalTestEntities())
     {
         var _id     = Guid.Parse(Id);
         var _RetObj = new UserViewModel();
         _RetObj = _context.tbl_usermaster.AsEnumerable().Select(t => t.ToModel()).FirstOrDefault(q => q.Id == _id);
         return(_RetObj);
     }
 }
Esempio n. 7
0
 public ActionResult DepartmentList()
 {
     try
     {
         using (PracticalTestEntities pt = new PracticalTestEntities())
         {
             List <DepartmentMaster> list = pt.DepartmentMasters.ToList();
             return(View(list));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 8
0
 public ActionResult DeleteDepartment(int id)
 {
     try
     {
         using (PracticalTestEntities pt = new PracticalTestEntities())
         {
             var Data = pt.DepartmentMasters.Where(x => x.DepartmentId == id).FirstOrDefault();
             pt.DepartmentMasters.Remove(Data);
             pt.SaveChanges();
         }
         return(RedirectToAction("Department", new { id = 0 }));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 9
0
 public ActionResult Delete(int id)
 {
     try
     {
         using (PracticalTestEntities pt = new PracticalTestEntities())
         {
             var Data = pt.Employees.Include("EmployeeDepartments").Where(x => x.EmployeeId == id).FirstOrDefault();
             pt.Employees.Remove(Data);
             pt.SaveChanges();
         }
         return(RedirectToAction("List"));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 10
0
        public bool InsertOrUpdate(UserViewModel User)
        {
            bool isUpdated = false;

            using (PracticalTestEntities _context = new PracticalTestEntities())
            {
                if (User.Id == null || User.Id == Guid.Empty)
                {
                    // Insert
                    tbl_usermaster _RetObj = new tbl_usermaster();
                    _RetObj.Id         = Guid.NewGuid();
                    _RetObj.Name       = User.Name;
                    _RetObj.Birthdate  = Convert.ToDateTime(User.Birthdate);
                    _RetObj.Email      = User.Email;
                    _RetObj.Mobile     = User.Mobile;
                    _RetObj.Age        = User.Age;
                    _RetObj.Gender     = User.Gender;
                    _RetObj.RoleId     = User.RoleId;
                    _RetObj.ProfileUrl = User.ProfileUrl;
                    _RetObj.IsActive   = true;
                    _RetObj.CreatedAt  = DateTime.Now;
                    _RetObj.UpdatedAt  = DateTime.Now;
                    _context.tbl_usermaster.Add(_RetObj);
                }
                else
                {
                    // Update
                    tbl_usermaster _RetObj = _context.tbl_usermaster.AsEnumerable().FirstOrDefault(q => q.Id == User.Id);
                    _RetObj.Id         = User.Id;
                    _RetObj.Name       = User.Name;
                    _RetObj.Birthdate  = Convert.ToDateTime(User.Birthdate);
                    _RetObj.Email      = User.Email;
                    _RetObj.Mobile     = User.Mobile;
                    _RetObj.Age        = User.Age;
                    _RetObj.Gender     = User.Gender;
                    _RetObj.RoleId     = User.RoleId;
                    _RetObj.ProfileUrl = User.ProfileUrl;
                    _RetObj.UpdatedAt  = DateTime.Now;
                }
                _context.SaveChanges();
                isUpdated = true;
            }
            return(isUpdated);
        }
Esempio n. 11
0
 /// <summary>
 /// Add Departments
 /// </summary>
 /// <param name="id">DepartmentId</param>
 /// <returns></returns>
 public ActionResult Department(int id = 0)
 {
     try
     {
         var Department = new DepartmentMaster();
         if (id > 0)
         {
             using (PracticalTestEntities pt = new PracticalTestEntities())
             {
                 Department = pt.DepartmentMasters.Where(x => x.DepartmentId == id).FirstOrDefault();
             }
         }
         return(View(Department));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 12
0
        public bool Exist(string Email, string id)
        {
            bool isUpdated = true;

            using (PracticalTestEntities _context = new PracticalTestEntities())
            {
                var            _id     = Guid.Parse(id);
                tbl_usermaster _RetObj = _context.tbl_usermaster.AsEnumerable().FirstOrDefault(q => q.Email == Email);

                if (_RetObj == null)
                {
                    isUpdated = false;
                }

                if (_id != Guid.Empty)
                {
                    isUpdated = _RetObj.Id != _id ? true : false;
                }
                return(isUpdated);
            }
        }
Esempio n. 13
0
        public bool Delete(string Id)
        {
            bool isUpdated = false;

            using (PracticalTestEntities _context = new PracticalTestEntities())
            {
                var            _id     = Guid.Parse(Id);
                tbl_usermaster _RetObj = _context.tbl_usermaster.AsEnumerable().FirstOrDefault(q => q.Id == _id);
                if (_RetObj.IsActive == true)
                {
                    _RetObj.IsActive = false;
                }
                else
                {
                    _RetObj.IsActive = true;
                }
                _context.SaveChanges();
                isUpdated = true;
                return(isUpdated);
            }
        }
Esempio n. 14
0
 public CommonService(PracticalTestEntities context)
 {
     this._context = context;
 }