예제 #1
0
 public void DeleteRequestDetail([FromBody] RequestViewModel reqDetail)
 {
     if (reqDetail != null)
     {
         RequestDAO.DeleteRequestDetail(reqDetail);
     }
 }
예제 #2
0
        public ActionResult DepartmentCart(List <RequestViewModel> Model, int?requestId, string btn_itemNo)
        {
            ViewBag.requestId = requestId;

            if (!ModelState.IsValid)
            {
                return(View(Model));
            }

            // Get current staff
            string userId = User.Identity.GetUserId();
            var    s1     = StaffDepartmentDAO.GetStaffByUserId(userId);

            #region delete button click
            if (btn_itemNo != null)
            {
                if (Model == null || Model.Count == 0)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                else
                {
                    switch (requestId)
                    {
                    // First time raise the request
                    case null:
                        var i1 = Model.Where(x => x.itemNo == btn_itemNo).First();
                        Model.Remove(i1);
                        ModelState.Clear();
                        Session["cartItems"] = Model.Select(x => x.itemNo).ToList();
                        return(View(Model));

                    default:
                        var reqDetail = new RequestViewModel()
                        {
                            requestId = requestId,
                            itemNo    = btn_itemNo
                        };
                        RequestDAO.DeleteRequestDetail(reqDetail);
                        var reqDetails = RequestDAO.GetRequestViewModelListByReqId((int)requestId);
                        ModelState.Clear();
                        return(View(reqDetails));
                    }
                }
            }
            #endregion

            #region submit button click
            if (Model == null || Model.Count == 0)
            {
                return(View());
            }

            bool bRes = false;
            switch (requestId)
            {
            // First time raise the request
            case null:

                //if (Model != null && Model.Count > 0)
                //{
                //    Model[0].staffId = s1.staffId;
                //    Model[0].departmentId = s1.departmentId;
                //}
                bRes = RequestDAO.RaiseRequest(s1.staffId, s1.departmentId, Model);
                if (bRes)
                {
                    // Clear the session value
                    Session["cartItems"] = null;
                }
                break;

            // Existed request
            default:
                bRes = RequestDAO.UpdateRequestDetails(Model);
                break;
            }

            if (bRes)
            {
                return(RedirectToAction("list"));
            }
            else
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            #endregion
        }