public ActionResult DeleteConfirmed(int id)
        {
            tbld_distribution_employee tbldDistributionEmployee = Db.tbld_distribution_employee.Find(id);

            if (tbldDistributionEmployee != null)
            {
                Db.tbld_distribution_employee.Remove(tbldDistributionEmployee);
            }
            Db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbld_distribution_employee tbldDistributionEmployee = Db.tbld_distribution_employee.Find(id);

            if (tbldDistributionEmployee == null)
            {
                return(HttpNotFound());
            }
            return(View(tbldDistributionEmployee));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbld_distribution_employee tbldDistributionEmployee = Db.tbld_distribution_employee.Find(id);

            if (tbldDistributionEmployee == null)
            {
                return(HttpNotFound());
            }

            if (tbldDistributionEmployee.active != null)
            {
                DBhouseemployeeVm dBhouseemployeeVm = new DBhouseemployeeVm()
                {
                    Id                       = tbldDistributionEmployee.id,
                    EmpCode                  = tbldDistributionEmployee.Emp_code,
                    Name                     = tbldDistributionEmployee.Name,
                    EmpAddress               = tbldDistributionEmployee.Emp_address,
                    UserRoleId               = tbldDistributionEmployee.User_role_id,
                    DistributionId           = tbldDistributionEmployee.DistributionId,
                    LoginUserId              = tbldDistributionEmployee.login_user_id,
                    LoginUserPassword        = tbldDistributionEmployee.login_user_password,
                    ContactNo                = tbldDistributionEmployee.contact_no,
                    JoiningDate              = tbldDistributionEmployee.joining_date,
                    Designation              = tbldDistributionEmployee.designation,
                    EmpType                  = tbldDistributionEmployee.Emp_Type,
                    Dob                      = tbldDistributionEmployee.d_o_b,
                    Email                    = tbldDistributionEmployee.email,
                    EmergencyContactPerson   = tbldDistributionEmployee.emergency_contact_person,
                    EmergencyContactNumber   = tbldDistributionEmployee.emergency_contact_number,
                    EducationalQualification = tbldDistributionEmployee.educational_qualification,
                    Image                    = tbldDistributionEmployee.image,
                    Active                   = (int)tbldDistributionEmployee.active
                };
                ViewBag.user_role = new SelectList(Db.user_role.Where(x => x.user_role_id == 7 || x.user_role_id == 8).ToList(), "user_role_id", "user_role_name");
                ViewBag.db        = new SelectList(Db.tbld_distribution_house.Where(x => x.Status == 1).ToList(), "DB_Id", "DBName");
                ViewBag.type      = new SelectList(Db.tbld_distribution_employee_Type.ToList(), "EmpTypeid", "EmpType");
                ViewBag.status    = new SelectList(Db.status.ToList(), "status_Id", "status_code");
                return(View(dBhouseemployeeVm));
            }
            return(HttpNotFound());
        }
        public ActionResult Edit(DBhouseemployeeVm dBhouseemployeeVm, HttpPostedFileBase image)
        {
            var imagePath = "~/App_res/empImage/";

            if (ModelState.IsValid)
            {
                string recentGenerateId = DateTime.Now.ToString("yyyy-MMddhhmmss");
                if (image != null)
                {
                    image.SaveAs(Server.MapPath(imagePath + recentGenerateId +
                                                System.IO.Path.GetExtension(image.FileName)));
                    if (System.IO.File.Exists(imagePath + image.FileName))
                    {
                        System.IO.File.Delete(imagePath + image.FileName);
                    }
                    dBhouseemployeeVm.Image = image.FileName;
                }
                else
                {
                    dBhouseemployeeVm.Image = "NA";
                }



                tbld_distribution_employee tbldDistributionEmployee = new tbld_distribution_employee()
                {
                    id                        = dBhouseemployeeVm.Id,
                    Emp_code                  = dBhouseemployeeVm.EmpCode,
                    Name                      = dBhouseemployeeVm.Name,
                    Emp_address               = dBhouseemployeeVm.EmpAddress,
                    User_role_id              = dBhouseemployeeVm.UserRoleId,
                    DistributionId            = dBhouseemployeeVm.DistributionId,
                    login_user_id             = dBhouseemployeeVm.LoginUserId,
                    login_user_password       = dBhouseemployeeVm.LoginUserPassword,
                    contact_no                = dBhouseemployeeVm.ContactNo,
                    joining_date              = dBhouseemployeeVm.JoiningDate,
                    designation               = dBhouseemployeeVm.Designation,
                    Emp_Type                  = dBhouseemployeeVm.EmpType,
                    d_o_b                     = dBhouseemployeeVm.Dob,
                    email                     = dBhouseemployeeVm.Email,
                    emergency_contact_person  = dBhouseemployeeVm.EmergencyContactPerson,
                    emergency_contact_number  = dBhouseemployeeVm.EmergencyContactNumber,
                    educational_qualification = dBhouseemployeeVm.EducationalQualification,
                    image                     = recentGenerateId,
                    active                    = dBhouseemployeeVm.Active
                };


                Db.Entry(tbldDistributionEmployee).State = EntityState.Modified;
                Db.SaveChanges();


                TempData["alertbox"]    = "success";
                TempData["alertboxMsg"] = dBhouseemployeeVm.Name + "  Update Successfully";
                return(RedirectToAction("Index"));
            }

            ViewBag.user_role = new SelectList(Db.user_role.Where(x => x.user_role_id == 7 || x.user_role_id == 8).ToList(), "user_role_id", "user_role_name");
            ViewBag.db        = new SelectList(Db.tbld_distribution_house.Where(x => x.Status == 1).ToList(), "DB_Id", "DBName");
            ViewBag.type      = new SelectList(Db.tbld_distribution_employee_Type.ToList(), "EmpTypeid", "EmpType");
            ViewBag.status    = new SelectList(Db.status.ToList(), "status_Id", "status_code");
            return(View(dBhouseemployeeVm));
        }