コード例 #1
0
        public ActionResult ProcessApproval(Approval approval)
        {
            var acResponse = new ActivityResponse();

            try
            {
                if (!User.Identity.IsAuthenticated)
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Your session has timed out. Please log in to continue";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }
                var userId          = User.Identity.GetUserId();
                var registeredUsers = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.Where(e => e.Id == userId).Include("UserInfo").ToList();
                if (!registeredUsers.Any())
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "An unknown error was encountered. Please try again or contact the support team.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                if (string.IsNullOrEmpty(approval.EnrollmentId))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "An unknown error was encountered. Please refresg the page and try again";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                if (approval.ApprovalStatus < 1)
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Please provide Approval Status";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                var baseDatas = _baseDataService.Query(b => b.EnrollmentId == approval.EnrollmentId).Select().ToList();
                var baseData  = baseDatas[0];
                baseData.DateLastUpdated = DateTime.Now;
                baseData.ApprovalStatus  = approval.ApprovalStatus;
                _unitOfWork.SaveChanges();

                approval.DateProcessed = baseData.DateLastUpdated;

                approval.ProcessedById = registeredUsers[0].UserInfo.Id;

                if (string.IsNullOrEmpty(approval.ApprovalId))
                {
                    approval.ApprovalId = Guid.NewGuid().ToString();
                    _approvalService.Insert(approval);
                    _unitOfWork.SaveChanges();
                }
                else
                {
                    _approvalService.Update(approval);
                    _unitOfWork.SaveChanges();
                }

                acResponse.Code    = 5;
                acResponse.Message = "Approval Process was successfully completed";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                acResponse.Code    = -1;
                acResponse.Message = "An unknown error was encountered. Please try again.";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
        }