Ejemplo n.º 1
0
        public ActionResult AuthorizeStaff()
        {
            DepartmentStaff a      = Session["DeptStaff"] as DepartmentStaff;
            string          deptId = a.DeptId;

            ViewData["tempHead"] = false;
            if (a.StaffId == a.Department.HeadId)
            {
                ViewData["tempHead"] = true;
            }
            DateTime today         = DateTime.Now;
            var      authorization = (from auth in db.Authorization
                                      join s in db.DepartmentStaff on auth.StaffId equals s.StaffId
                                      where auth.DeptId == deptId
                                      where auth.EndDate >= today
                                      select new AuthorizationViewModel
            {
                staffName = s.StaffName,
                auth = auth
            }).ToList();

            //var authorization = db.Authorization.Where(x=>x.DeptId==deptId && x.StartDate>=today).ToList();
            ViewData["AuthList"] = authorization;
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult OrderStatus()
        {
            DepartmentStaff a     = Session["DeptStaff"] as DepartmentStaff;
            String          temp  = Convert.ToBoolean(Session["TempHead"]).ToString();
            String          check = Convert.ToBoolean(Session["CheckHead"]).ToString();

            ViewData["ApproveOrNot"] = null;
            var request = db.Request.Where(x => x.DeptId == a.DeptId).Include(d => d.Department);

            if (a.StaffType == "head")
            {
                ViewData["ApproveOrNot"] = true;
            }
            else if (a.StaffType != "head" && temp == "True")
            {
                ViewData["ApproveOrNot"] = true;
            }
            else
            {
                request = request.Where(x => x.StaffId == a.StaffId).Include(d => d.Department);
            }
            if (a.StaffType == "head" && check == "True")
            {
                ViewData["ApproveOrNot"] = null;
            }
            ViewData["header"] = "Order Status";
            return(View(request.ToList()));
        }
Ejemplo n.º 3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            DepartmentStaff ds       = (DepartmentStaff)filterContext.HttpContext.Session["DeptStaff"];
            bool            tempHead = (bool)filterContext.HttpContext.Session["TempHead"];

            if (Roles == "All")
            {
                if ((DepartmentStaff)filterContext.HttpContext.Session["DeptStaff"] != null)
                {
                    return;
                }
            }
            else
            {
                string[] roles = Roles.Split(',');
                foreach (var role in roles)
                {
                    if ((DepartmentStaff)filterContext.HttpContext.Session["DeptStaff"] != null && ds.StaffType == role || tempHead == true)
                    {
                        return;
                    }
                }
            }
            filterContext.HttpContext.Response.Redirect(Uri.EscapeUriString("/Home/Error"));
            base.OnActionExecuting(filterContext);
        }
Ejemplo n.º 4
0
        public ActionResult RequestApproval(string approve, string reject, string remarks, int id)
        {
            DepartmentStaff ds     = Session["DeptStaff"] as DepartmentStaff;
            Request         rd     = db.Request.Find(id);
            List <string>   emails = new List <string>();
            string          email  = db.DepartmentStaff.Where(x => x.StaffId == rd.StaffId).Select(x => x.StaffEmail).FirstOrDefault();

            emails.Add(email);
            if (approve == "Approve")
            {
                rd.Status = approve;
                rd.Remark = remarks;
                db.SaveChanges();
            }
            else if (reject == "Reject")
            {
                rd.Status = reject;
                rd.Remark = remarks;
                db.SaveChanges();
            }
            string message = Utility.EmailBody.ApproveBody + approve + ". Check for the reason  http://127.0.0.1:64451/Request/OrderStatus";

            Utility.EmailService.SendEmail(emails, Utility.EmailBody.ApproveSubject + approve, message);
            return(RedirectToAction("OrderStatus"));
        }
Ejemplo n.º 5
0
        public ActionResult SetDisbursementList(int id, string status, string deptId)
        {
            string[] productIds    = Request.Form.GetValues("productId");
            string[] requestedQtys = Request.Form.GetValues("requestedQty");
            string[] receivedQtys  = Request.Form.GetValues("receivedQty");
            string[] remarks       = Request.Form.GetValues("remarks");
            int      storeStaffId  = Convert.ToInt32(Request.Form.Get("creatorId"));

            //Update the item quantities && Set Disburesment status to delivered
            disbursementDAO.SaveDisbursement(id, status, receivedQtys, remarks, storeStaffId);
            DepartmentStaff rep = departmentStaffDAO.getDeptRep(deptId);

            //Set all the orders status to Delivered. Not DAO-ed
            using (db = new LogicEntities())
            {
                var resultSet = from r in db.Request
                                where r.DeptId == deptId
                                select r;
                List <Request> requests = resultSet.ToList();
                foreach (Request req in requests)
                {
                    req.Status          = "Delivered";
                    db.Entry(req).State = EntityState.Modified;
                    db.SaveChanges();
                }
                //if Qty received < Qty Requested, Generate outstanding order in requests

                Request outstanding = new Request
                {
                    DeptId  = deptId,
                    ReqDate = DateTime.Now,
                    Remark  = "Outstanding Order, " + DateTime.Now.Date.ToString("d"),
                    Status  = "Outstanding",
                    StaffId = rep.StaffId
                };
                List <RequestDetail> outstandingDetails = new List <RequestDetail>();
                for (int x = 0; x < requestedQtys.Length; x++)
                {
                    if (requestedQtys[x] != receivedQtys[x])
                    {
                        RequestDetail rd = new RequestDetail
                        {
                            ProductId   = productIds[x],
                            RequestId   = outstanding.RequestId,
                            ReqQty      = Convert.ToInt32(requestedQtys[x]) - Convert.ToInt32(receivedQtys[x]),
                            ReceivedQty = 0, //Shouldn't be needed...
                        };
                        outstandingDetails.Add(rd);
                    }
                }
                if (outstandingDetails.Count != 0)
                {
                    db.Request.Add(outstanding);
                    db.RequestDetail.AddRange(outstandingDetails);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("FindDisbursementList"));
        }
Ejemplo n.º 6
0
        public ActionResult GetLocation()
        {
            DepartmentStaff a = Session["DeptStaff"] as DepartmentStaff;
            var             c = db.Department.Where(x => x.DeptId == a.DeptId).FirstOrDefault();

            ViewData["collectionPoint"] = c.CollectionPt;
            return(View(db.CollectionPoint));
        }
        private void DepartmentStaff_Click(object sender, RoutedEventArgs e)
        {
            List.Children.Clear();
            DepartmentStaff DepartmentStaff = new DepartmentStaff();

            List.Children.Add(DepartmentStaff);
            DepartmentStaff.SetValue(Grid.RowProperty, 0);
            DepartmentStaff.SetValue(Grid.ColumnProperty, 3);
            DepartmentStaff.SetValue(Grid.ColumnSpanProperty, 12);
        }
Ejemplo n.º 8
0
        public ActionResult AppointRepresentative()
        {
            DepartmentStaff        a    = Session["DeptStaff"] as DepartmentStaff;
            Department             d    = db.Department.Where(x => x.DeptId == a.DeptId).FirstOrDefault();
            List <DepartmentStaff> list = db.DepartmentStaff.ToList();
            String name = list.Where(x => x.StaffId == d.RepId).Select(x => x.StaffName).FirstOrDefault();

            ViewData["CurrentRep"] = name;
            return(View());
        }
Ejemplo n.º 9
0
        //public ActionResult OutstandingDisbursementList()
        //{
        //    DateTime cutoff = DateTime.Now.Date;
        //    List<Department> departments = new List<Department>();
        //    departments = departmentDAO.GetDepartmentsWithOutstandingOrders(cutoff);

        //    ViewData["departments"] = departments;

        //    return View();
        //}

        public ActionResult GenerateDisbursementLists()
        {
            DateTime          cutoff      = DateTime.Now.Date; //Ensures that orders only up to yesterday 2359 is taken into consideration
            List <Department> departments = departmentDAO.GetDepartmentsWithOutstandingOrders(cutoff);
            List <DisbursementDetailViewModel> consolidatedOrders = new List <DisbursementDetailViewModel>();

            foreach (Department d in departments)
            {
                DepartmentStaff rep = departmentStaffDAO.getDeptRep(d.DeptId);
                using (db = new LogicEntities())
                {
                    var resultSet = from rd in db.RequestDetail
                                    from r in db.Request
                                    where (r.Status.Contains("New") || r.Status.Contains("Outstanding")) &&
                                    r.RequestId == rd.RequestId && r.DeptId == d.DeptId &&
                                    r.ReqDate < cutoff
                                    group rd by new { rd.ProductId, r.DeptId } into g
                        select new DisbursementDetailViewModel            //Note to self: Groupby only works with enums or primitive data types
                    {
                        ProductId    = g.Key.ProductId,
                        DepartmentId = g.Key.DeptId,
                        Quantity     = g.Sum(x => x.ReqQty)
                    };
                    consolidatedOrders = resultSet.ToList();

                    Disbursement dis = new Disbursement
                    {
                        DisDate           = DateTime.Now,
                        Status            = "Pending",
                        DeptId            = d.DeptId,
                        StoreStaffId      = null,
                        ReceiveStaffId    = rep.StaffId,
                        CollectionPointId = d.CollectionPt
                    };
                    List <DisbursementDetail> disbursementdetails = new List <DisbursementDetail>();
                    foreach (DisbursementDetailViewModel p in consolidatedOrders)
                    {
                        DisbursementDetail dd = new DisbursementDetail
                        {
                            ProductId   = p.ProductId,
                            RequiredQty = p.Quantity,
                            ReceivedQty = 0,
                            DisId       = dis.DisId
                        };
                        disbursementdetails.Add(dd);
                    }
                    db.Disbursement.Add(dis);
                    db.DisbursementDetail.AddRange(disbursementdetails);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("FindDisbursementList"));
        }
Ejemplo n.º 10
0
        public ActionResult CreateFavOrder(string products, string qty, string nameId)
        {
            DepartmentStaff ds = Session["DeptStaff"] as DepartmentStaff;

            if (products != "" && ModelState.IsValid)
            {
                FavOrderDAO.AddRequest(products, qty, ds.StaffId, nameId);
                return(RedirectToAction("ViewFaveOrder"));
            }

            return(RedirectToAction("ViewFaveOrder"));
        }
Ejemplo n.º 11
0
        public BaseResponse <ComplexStaffDepartment> AddStaffsDepartment(List <ComplexStaffDepartment> models)
        {
            var             response     = new BaseResponse <ComplexStaffDepartment>();
            DepartmentStaff obj          = new DepartmentStaff();
            string          userId       = "";
            int             departmentId = 0;

            try
            {
                foreach (var item in models)
                {
                    userId       = item.EditedBy;
                    departmentId = item.DepartmentId;
                    DepartmentStaff st = _departmentStaffsRepository.GetAll().FirstOrDefault(n => n.StaffId == item.StaffId && n.DepartmentId == item.DepartmentId);
                    if (st != null)
                    {
                        st.Position       = item.Position;
                        st.EditedBy       = item.EditedBy;
                        st.EditedOn       = DateTime.Now;
                        st.MainDepartment = true;
                        _departmentStaffsRepository.Edit(st);
                    }
                    else
                    {
                        obj.StaffId        = item.StaffId;
                        obj.DepartmentId   = item.DepartmentId;
                        obj.MainDepartment = true;
                        obj.ShortPosition  = "";
                        obj.Position       = item.Position;
                        obj.CreatedOn      = DateTime.Now;
                        obj.CreatedBy      = item.EditedBy;
                        obj.EditedOn       = DateTime.Now;
                        obj.EditedBy       = item.EditedBy;
                        _departmentStaffsRepository.Add(obj);
                    }
                }
                try
                {
                    _applicationLoggingRepository.Log("EVENT", "ADD", "DepartmentStaff", departmentId.ToString(), "", "", null, "", HttpContext.Current.Request.UserHostAddress, userId);
                }
                catch
                {
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }
Ejemplo n.º 12
0
        public JsonResult DepartmentLoginApi(string username, string password)
        {
            if (username == null || password == null)
            {
                return(Json(new { isok = false, message = "Login Unsuccessful" }));
            }
            DepartmentStaff user = db.DepartmentStaff.Where(x => x.Username == username && x.Password == password).SingleOrDefault();

            if (user == null)
            {
                return(Json(new { isok = false, message = "Login Unsuccessful" }));
            }
            return(Json(new { isok = true, message = "Login Successful", Id = user.StaffId }));
        }
Ejemplo n.º 13
0
        public ActionResult GetLocationAsync(int locationId)
        {
            DepartmentStaff ds     = Session["DeptStaff"] as DepartmentStaff;
            string          DeptId = ds.DeptId;
            Department      d      = db.Department.Where(x => x.DeptId == DeptId).SingleOrDefault();

            d.CollectionPt = locationId;
            db.SaveChanges();
            List <String> list    = db.StoreStaff.Select(x => x.StaffEmail).ToList();
            string        message = Utility.EmailBody.CollectionSubject + "\n" + "By " + d.DeptName;

            Utility.EmailService.SendEmail(list, Utility.EmailBody.CollectionSubject, message);
            //await e.SendEmailAsync("*****@*****.**", "hello", "das");

            return(Json(new { isok = true, message = "Collection Point is set.", redirect = "/Departments/Dashboard", locationId = locationId }));
        }
Ejemplo n.º 14
0
        public ActionResult PostLocationApi(int locationId, int staffId)
        {
            //DepartmentStaff ds = Session["DeptStaff"] as DepartmentStaff;
            DepartmentStaff ds     = db.DepartmentStaff.Where(x => x.StaffId == staffId).FirstOrDefault();
            string          DeptId = ds.DeptId;
            Department      d      = db.Department.Where(x => x.DeptId == DeptId).SingleOrDefault();

            d.CollectionPt = locationId;
            db.SaveChanges();
            List <String> list    = db.StoreStaff.Select(x => x.StaffEmail).ToList();
            string        message = Utility.EmailBody.CollectionBody + "\n" + "By " + d.DeptName;

            Utility.EmailService.SendEmail(list, Utility.EmailBody.CollectionSubject, message);

            return(Json(new { isok = true, message = "Collection Point is set." }));
        }
Ejemplo n.º 15
0
        public IActionResult CreateDepartmentStaff(int depId, string userId)
        {
            if (ModelState.IsValid)
            {
                var entity = new DepartmentStaff()
                {
                    DepartmentId = depId,
                    UserId = userId
                };

                _departmentStaffService.Create(entity);

                return RedirectToAction("ListDepartmentStaff");
            }

            return View();
        }
Ejemplo n.º 16
0
        public ActionResult CreateRequest(string products, string qty)
        {
            DepartmentStaff a = Session["DeptStaff"] as DepartmentStaff;

            if (products != "" && ModelState.IsValid)
            {
                List <string> head = new List <string>();
                RequestDAO.AddRequest(products, qty, a.StaffId);
                string headname = db.DepartmentStaff.Where(x => x.DeptId == a.DeptId && x.StaffType == "head").Select(x => x.StaffEmail).FirstOrDefault();
                head.Add(headname);
                string message = Utility.EmailBody.RequestBody + a.StaffName + Utility.EmailBody.RequestBody2;
                Utility.EmailService.SendEmail(head, Utility.EmailBody.RequestSubject, message);
                return(RedirectToAction("OrderStatus", "Request"));
            }
            TempData["shortMessage"] = "Please choose at least a product to create a request form";
            return(RedirectToAction("RequestForm", "Request"));
        }
Ejemplo n.º 17
0
        private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string save;

            try
            {
                if (this.Name == "DepartmentTable")
                {
                    save = ((DataRowView)this.dataGrid.SelectedItem).Row["DepId"].ToString();
                    DepartmentStaff select = new DepartmentStaff();
                    select.StaffTable.DataTableSelect("select * from ArmsPerson where Dep_Id ='" + save + "'", "更新");
                }
            }
            catch (Exception se)
            {
                MessageBox.Show(se.ToString());
            }
        }
Ejemplo n.º 18
0
        //Get the list of staff - Hui Chin
        public JsonResult GetStaffList(string searchTerm)
        {
            DepartmentStaff a         = Session["DeptStaff"] as DepartmentStaff;
            var             staffList = db.DepartmentStaff.Where(x => x.StaffType != "head" && x.DeptId == a.DeptId).ToList();

            if (searchTerm != null)
            {
                staffList = db.DepartmentStaff.Where(x => x.StaffName.Contains(searchTerm)).ToList();
            }

            var modifiedData = staffList.Select(x => new
            {
                id   = x.StaffId,
                text = x.StaffName
            });

            return(Json(modifiedData, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 19
0
        public ActionResult DepartmentLogin(string username, string password)
        {
            string session = (string)Session["DeptSession"];

            if (session != null)
            {
                return(RedirectToAction("Dashboard", "Departments"));
            }
            if (username == null || password == null)
            {
                return(View());
            }
            DepartmentStaff user = db.DepartmentStaff.Where(x => x.Username == username && x.Password == password).SingleOrDefault();

            if (user == null)
            {
                return(View());
            }
            DateTime      today         = DateTime.Now;
            string        deptId        = user.DeptId;
            Authorization authorization = db.Authorization.Where(x => x.StaffId == user.StaffId && x.StartDate <= today && x.EndDate >= today).FirstOrDefault();
            Authorization checkHead     = db.Authorization.Where(x => x.DeptId == deptId && x.StartDate <= today && x.EndDate >= today).FirstOrDefault();
            string        sessionId     = Guid.NewGuid().ToString();

            if (user != null)
            {
                user.SessionId = sessionId;
                db.SaveChanges();
            }
            Session["DeptSession"] = sessionId;
            Session["DeptStaff"]   = user;
            Session["TempHead"]    = false;
            Session["CheckHead"]   = false;
            if (checkHead != null)
            {
                Session["CheckHead"] = true;
            }
            if (authorization != null)
            {
                Session["TempHead"] = true;
            }
            return(RedirectToAction("Dashboard", "Departments"));
        }
Ejemplo n.º 20
0
        public ActionResult DetailedDisbursementList(int id)
        {
            Disbursement disbursement = new Disbursement();
            Department   department   = new Department();
            List <DisbursementDetail> disbursementDetails = new List <DisbursementDetail>();
            List <Product>            disbursedProducts   = new List <Product>();
            StoreStaff      storeStaff = new StoreStaff(); //To create via the session object
            DepartmentStaff receiver   = new DepartmentStaff();
            CollectionPoint cp         = new CollectionPoint();

            using (db = new LogicEntities())
            {
                var result = from d in db.Disbursement
                             where d.DisId == id
                             select d;
                disbursement        = result.First();
                department          = disbursement.Department;
                disbursementDetails = disbursement.DisbursementDetails.ToList();
                foreach (DisbursementDetail dd in disbursementDetails)
                {
                    disbursedProducts.Add(dd.Product);
                }
            }
            if (disbursement.StoreStaffId != null)
            {
                storeStaff = storestaffDAO.GetStaffbyId(disbursement.StoreStaffId.Value);
            }
            else
            {
                storeStaff = (StoreStaff)Session["StoreStaff"];//StoreStaff from session
            }
            receiver                        = departmentStaffDAO.GetStaffById(disbursement.ReceiveStaffId);
            cp                              = collectionPointDAO.GetCollectionPoint(disbursement.CollectionPointId);
            ViewData["receiver"]            = receiver;
            ViewData["storestaff"]          = storeStaff;
            ViewData["disbursement"]        = disbursement;
            ViewData["disbursementdetails"] = disbursementDetails;
            ViewData["CollectionPoint"]     = cp;
            return(View());
        }
Ejemplo n.º 21
0
        public BaseResponse <DepartmentStaff> AddDepartmentStaff(DepartmentStaff model)
        {
            var response = new BaseResponse <DepartmentStaff>();
            var errors   = Validate <DepartmentStaff>(model, new DepartmentStaffsValidator());

            if (errors.Count() > 0)
            {
                BaseResponse <DepartmentStaff> errResponse = new BaseResponse <DepartmentStaff>(model, errors);
                errResponse.IsSuccess = false;
                return(errResponse);
            }
            try
            {
                if (model.MainDepartment == true)
                {
                    IEnumerable <DepartmentStaff> ds = _departmentStaffsRepository.GetAll().Where(n => n.StaffId == model.StaffId && n.DepartmentId == n.DepartmentId).ToList();
                    if (ds.Count() > 0)
                    {
                        _departmentStaffsRepository.DeleteMulti(x => x.StaffId == model.StaffId && x.DepartmentId == model.DepartmentId);
                    }
                }
                model.CreatedOn = DateTime.Now;
                response.Value  = _departmentStaffsRepository.Add(model);
                try
                {
                    _applicationLoggingRepository.Log("EVENT", "ADD", "DepartmentStaff", model.DepartmentId + "," + model.StaffId.ToString(), "", "", model, "", HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                }
                catch
                { }
                //}
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }
Ejemplo n.º 22
0
 public ActionResult Logout(string type)
 {
     if (type == "d")
     {
         string          session = (string)Session["DeptSession"];
         DepartmentStaff ds      = db.DepartmentStaff.Where(x => x.SessionId == session).SingleOrDefault();
         ds.SessionId = null;
         Session.Remove("DeptSession");
         Session.Remove("DeptStaff");
         Session.Remove("TempHead");
         db.SaveChanges();
         return(RedirectToAction("DepartmentLogin"));
     }
     else
     {
         string     session = (string)Session["StoreSession"];
         StoreStaff ss      = db.StoreStaff.Where(x => x.SessionId == session).SingleOrDefault();
         ss.SessionId = null;
         Session.Remove("StoreSession");
         Session.Remove("StoreStaff");
         db.SaveChanges();
         return(RedirectToAction("StoreLogin"));
     }
 }
Ejemplo n.º 23
0
 public void Create(DepartmentStaff entity)
 {
     _DepartmentStaffDal.Create(entity);
 }
 public BaseResponse <DepartmentStaff> Add(DepartmentStaff model)
 {
     return(organizationService.AddDepartmentStaff(model));
 }
Ejemplo n.º 25
0
 public void Update(DepartmentStaff entity)
 {
     _DepartmentStaffDal.Update(entity);
 }
Ejemplo n.º 26
0
 public void Delete(DepartmentStaff entity)
 {
     _DepartmentStaffDal.Delete(entity);
 }