예제 #1
0
        public JsonResult ConfirmReceive()
        {
            //load the signinglist
            Dictionary <int, int> signinglist = new Dictionary <int, int>();

            if (Session["signinglist"] != null)
            {
                signinglist = (Dictionary <int, int>)Session["signinglist"];
            }
            else
            {
                throw new Exception("please sign in to confirm receivement");
            }

            int depId;

            if (Session["username"] != null)
            {
                Employee u = EmployeeData.FindByUserName((string)Session["username"]);
                depId = u.department.Id;
            }
            else
            {
                throw new Exception("please sign in to confirm receivement");
            }


            bool notifystatus = false;

            foreach (int itemId in signinglist.Keys)
            {
                // SRequisition sr = new SRequisition();
                //sr.ListItem = new List<ReqItem>();

                foreach (int empId in DepartmentData.GetDepById(depId).Employees.Select(x => x.Id))
                {
                    if (ReqItemData.SetReqItemDeliveredToRep(empId, itemId) && notifystatus == false)
                    {
                        string emailaddress = EmployeeData.FindEmpById(empId).EmailAdd;
                        Task   task         = Task.Run(() =>
                        {
                            EmailNotification.SendNotificationEmailToEmployee(emailaddress, "Stationary Requisition Status Changed", "Your Stationary Requisition has delivered to Department Representative.");
                        });
                        notifystatus = true;
                    }
                }


                //if any discrepancy, create new reqItem to replenish in next delivery.
                int dif = DepOrderData.GetDeliveringOrderByDepAndItem(depId, itemId).quant - signinglist[itemId];

                if (dif > 0)
                {
                    int i = itemId;
                    int j = DepartmentData.GetRepById(depId);
                    ReqItemData.CreatReqItem(itemId, DepartmentData.GetRepById(depId), dif, "approved");
                    /////////////////////////
                }

                //mark this DepOrder to be delivered
                DepOrderData.SetReceived(depId, itemId, signinglist[itemId]);
            }
            Session.Remove("signinglist");



            object new_amount = new { };

            return(Json(new_amount, JsonRequestBehavior.AllowGet));
        }