public JsonResult GetDesignationMasterByDepartment(DepartmentMasterModel collection)
        {
            try
            {
                List <DesignationMasterModel> _list = new List <DesignationMasterModel>();
                var _objDesignationMaster           = _DbWorkPermitSystemEntities.tbl_DesignationMaster.Where(p => p.DepartmentID == collection.DepartmentID).ToList();
                foreach (var item in _objDesignationMaster)
                {
                    DesignationMasterModel _class = new Models.DesignationMasterModel();

                    _class.DesignationID   = item.DesignationID;
                    _class.DepartmentID    = item.DepartmentID;
                    _class.DesignationName = item.DesignationName;
                    _list.Add(_class);
                }

                return(Json(_list, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ResultModel _objResult = new ResultModel();
                _objResult.success = 0;
                _objResult.msg     = ex.ToString();
                return(Json(_objResult, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Edit(int id, DepartmentMasterModel collection)
        {
            // TODO: Add update logic here
            //DepartmentMasterModel _objDepartment = new DepartmentMasterModel();
            try
            {
                CheckViewBagData();
                if (ModelState.IsValid)
                {
                    var data = _DbWorkPermitSystemEntities.tbl_DepartmentMaster.Where(b => b.DepartmentID == id).FirstOrDefault();
                    {
                        //data.DepartmentID = collection.DepartmentID;
                        data.DepartmentName = collection.DepartmentName;
                        _DbWorkPermitSystemEntities.Entry(data).State = EntityState.Modified;
                        _DbWorkPermitSystemEntities.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }


                return(View());
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Exemplo n.º 3
0
        public IEnumerable <DepartmentMasterModel> GetAllDepartmentList(string databasename)
        {
            string strConnection = "";

            strConnection = "Server=localhost;user id=root;password=pari@123;Database=" + databasename + "";

            List <DepartmentMasterModel> data = new List <DepartmentMasterModel>();
            MySqlConnection myConn            = new MySqlConnection();
            MySqlCommand    myCmd             = new MySqlCommand();
            MySqlDataReader myRdr             = null;

            try
            {
                myConn.ConnectionString = strConnection;
                myConn.Open();
                myCmd.Connection  = myConn;
                myCmd.CommandType = CommandType.Text;
                myCmd.CommandText = "SELECT Department_Code,Department_Name FROM tbldepartment Order By Department_Name";
                myRdr             = myCmd.ExecuteReader();

                if (myRdr.HasRows)
                {
                    while (myRdr.Read())
                    {
                        DepartmentMasterModel singledata = new DepartmentMasterModel();
                        singledata.DepartmentId   = Convert.ToInt16(myRdr["Department_Code"].ToString());
                        singledata.DepartmentName = myRdr["Department_Name"].ToString();
                        data.Add(singledata);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (myRdr != null)
                {
                    myRdr.Close();
                    myRdr.Dispose();
                    myRdr = null;
                }

                if (myCmd != null)
                {
                    myCmd.Dispose();
                    myCmd = null;
                }
                if (myConn != null)
                {
                    myConn.Close();
                    myConn.Dispose();
                    myConn = null;
                }
            }
            return(data);
        }
        // GET: EmployeeDepartment/Details/5
        public ActionResult Details(int id)
        {
            CheckViewBagData();
            var model = _DbWorkPermitSystemEntities.tbl_DepartmentMaster.Where(a => a.DepartmentID == id).FirstOrDefault();
            DepartmentMasterModel _objDepartmentModel = new DepartmentMasterModel();

            _objDepartmentModel.DepartmentID         = model.DepartmentID;
            _objDepartmentModel.DepartmentName       = model.DepartmentName;
            _objDepartmentModel.DepartmentCreateDate = model.DepartmentCreateDate;
            return(View(_objDepartmentModel));
        }
        public ActionResult Create(DepartmentMasterModel collection)
        {
            CheckViewBagData();
            if (ModelState.IsValid)
            {
                var data = new tbl_DepartmentMaster()
                {
                    DepartmentName       = collection.DepartmentName,
                    DepartmentCreateDate = DateTime.Now
                };
                if (!_DbWorkPermitSystemEntities.tbl_DepartmentMaster.Any(p => p.DepartmentName == collection.DepartmentName))
                {
                    try
                    {
                        _DbWorkPermitSystemEntities.tbl_DepartmentMaster.Add(data);
                        _DbWorkPermitSystemEntities.SaveChanges();


                        List <string> Desig = new List <string> {
                            "Activity Owner", "Area Owner"
                        };
                        foreach (var item in Desig)
                        {
                            var DesignationData = new tbl_DesignationMaster()
                            {
                                DepartmentID          = _DbWorkPermitSystemEntities.tbl_DepartmentMaster.Where(p => p.DepartmentName == collection.DepartmentName).Select(p => p.DepartmentID).FirstOrDefault(),
                                DesignationName       = item,
                                DesignationCreateDate = DateTime.Now
                            };
                            _DbWorkPermitSystemEntities.tbl_DesignationMaster.Add(DesignationData);
                            _DbWorkPermitSystemEntities.SaveChanges();
                        }
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Errormessage = "Fail";
                }
            }
            return(View());
        }
        public ActionResult Index()
        {
            CheckViewBagData();
            List <DepartmentMasterModel> _objDepartmentModel = new List <DepartmentMasterModel>();
            var Department = _DbWorkPermitSystemEntities.tbl_DepartmentMaster.ToList();

            foreach (var item in Department)
            {
                DepartmentMasterModel _objDepartmentMasterModel = new DepartmentMasterModel();
                var Departmentitem = _DbWorkPermitSystemEntities.tbl_DepartmentMaster.Where(p => p.DepartmentID == item.DepartmentID).FirstOrDefault();
                _objDepartmentMasterModel.DepartmentID         = Departmentitem.DepartmentID;
                _objDepartmentMasterModel.DepartmentName       = Departmentitem.DepartmentName;
                _objDepartmentMasterModel.DepartmentCreateDate = Departmentitem.DepartmentCreateDate;
                _objDepartmentModel.Add(_objDepartmentMasterModel);
            }
            return(View(_objDepartmentModel.ToList()));
        }