Exemple #1
0
        public ActionResult SaveDisbursement(int[] IdItemRetrieved)
        {
            // Assume ClerkID
            int IdStoreClerk = (int)Session["IdEmployee"];

            // Get Department that seleceted same collection point as store clerk
            List <string> DClerk = _disbursementDAO.ReturnStoreClerkCP(IdStoreClerk);

            if (IdItemRetrieved.Any())
            {
                // Get IdDisbursementItem from Selecte Retrieved Item
                List <int> IdDisbursementItem = _disbursementItemDAO.GetIdByItemRetrieved(DClerk, IdItemRetrieved);
                // update disbursementitem and set status to "prepared"
                // return IdDisbursement with at lease one items have been set as "prepared"
                List <int> IdDisbursement = _disbursementItemDAO.UpdateDisbursementItem(IdDisbursementItem);
                // update disbursement and set status to "prepared"
                _disbursementDAO.UpdateDisbursement(IdDisbursement);
                // update item stock unit and available unit
                _itemDAO.UpdateItem(IdDisbursementItem);

                // update stockrecord
                _stockRecordDAO.UpdateStockRecord(IdStoreClerk, IdDisbursementItem);

                // check if stock unit is less reorder level
                bool IsLowerThanReorderLevel = _itemDAO.CheckIfLowerThanReorderLevel(IdItemRetrieved);

                if (IsLowerThanReorderLevel)
                {
                    // @Shutong: raise alert to all stockclerks, their ID are 1,2,3
                    Employee        storeclerk1 = new Employee();
                    Employee        storeclerk2 = new Employee();
                    Employee        storeclerk3 = new Employee();
                    List <Employee> clerks      = _employeeDAO.FindAllClerk();
                    if (clerks.Count >= 3)
                    {
                        storeclerk1 = clerks[0];
                        storeclerk2 = clerks[1];
                        storeclerk3 = clerks[2];
                    }

                    var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                    hub.Clients.All.receiveNotification(1);
                    hub.Clients.All.receiveNotification(2);
                    hub.Clients.All.receiveNotification(3);
                    EmailClass emailClass = new EmailClass();
                    string     message    = "The stock levels of some items are running low!";
                    _notificationChannelDAO.CreateNotificationsToGroup("Clerk", IdStoreClerk, message);
                    emailClass.SendTo(storeclerk1.Email, "SSIS System Email", message);
                    emailClass.SendTo(storeclerk2.Email, "SSIS System Email", message);
                    emailClass.SendTo(storeclerk3.Email, "SSIS System Email", message);
                }
            }
            else
            {
                return(RedirectToAction("FormRetrieve", "StoreClerk"));
            }
            return(RedirectToAction("FormRetrieve", "StoreClerk"));
        }