Пример #1
0
        public JsonResult Delete(long id)
        {
            try
            {
                logger.DebugFormat("Deleting Requisition With ID [{0}] ", id);

                if (!PermissionControl.CheckPermission(UserAppPermissions.Requisition_Delete))
                {
                    logger.Info("Don't have right to delete Requisition record");
                    return(Json(new { Message = Resources.Messages.MSG_RESTRICTED_ACCESS, MessageClass = MessageClass.Error, Response = false }));
                }

                Requisition req = requisitionManagement.GetRequisition(id);

                req.IsDeleted = true;
                if (requisitionManagement.Update(req))
                {
                    requisitionManagement.SaveRequisition();
                    logger.Info("Requisition record Successfully Deleted");
                    var allocation = userAllocationManagement.GetUserAllocationsByRequisition(id);
                    if (allocation != null)
                    {
                        logger.DebugFormat("Deleting User Allocation With Requisition ID [{0}] ", id);
                        foreach (var userAllocation in allocation)
                        {
                            userAllocation.Status     = RequestStatus.Deleted;
                            userAllocation.ModifiedBy = new Guid(User.Identity.GetUserId());
                            userAllocation.IsActive   = false;
                            userAllocationManagement.Update(userAllocation);
                        }
                        userAllocationManagement.SaveUserAllocation();
                        logger.Info("User Allocation records Successfully Deleted");
                    }

                    return(Json(new { Message = Resources.Messages.MSG_GENERIC_DELETE_SUCCESS, MessageClass = MessageClass.Success, Response = true }));
                }
                else
                {
                    logger.Info("Requisition record not deleted");
                    return(Json(new { Message = Resources.Messages.MSG_GENERIC_DELETE_FAILED, MessageClass = MessageClass.Error, Response = false }));
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace);
                return(Json(new { Message = Resources.Messages.MSG_GENERIC_DELETE_FAILED, MessageClass = MessageClass.Error, Response = false }));
            }
        }
        public JsonResult Operation(string id_type, string comments)
        {
            try
            {
                var values = id_type.Split('_');
                logger.DebugFormat(" User Allocation updated with  With ID [{0}] and action [{1}] ", values[0], values[1]);

                if (!PermissionControl.CheckPermission(UserAppPermissions.UserAllocation_Approve_Reject))
                {
                    logger.Info("Don't have right to Approve/Reject User Allocation record");
                    return(Json(new { Message = Resources.Messages.MSG_RESTRICTED_ACCESS, MessageClass = MessageClass.Error, Response = false }));
                }

                UserAllocation req = userAllocationManagement.GetUserAllocation(Convert.ToInt64(values[0]));
                if (req == null)
                {
                    return(Json(new { Message = "User Allocation not found", MessageClass = MessageClass.Error, Response = false }));
                }

                string selectedType = Convert.ToInt32(values[1]) == 1 ? RequestStatus.Approved : RequestStatus.Rejected;
                if (req.UserID != null && selectedType == RequestStatus.Rejected) // If user is not null and operation is rejected
                {
                    req.Comments = comments;
                    DeActiveUserGroupAllocation(req);
                }
                if (selectedType == RequestStatus.Approved)
                {
                    req.IsActive = true;
                    req.Status   = RequestStatus.PartialApproved;
                }
                else
                {
                    req.IsActive = true;
                    req.Status   = RequestStatus.Rejected;
                }

                req.ModifiedBy = new Guid(User.Identity.GetUserId());
                req.Comments   = comments;


                if (userAllocationManagement.Update(req))
                {
                    userAllocationManagement.SaveUserAllocation();
                    logger.InfoFormat("User Allocation record Successfully {0}", selectedType);

                    if (req.RequisitionID.HasValue)
                    {
                        UpdateRequisitionStatus(req, selectedType);
                    }

                    if (req.UserID != null && selectedType == RequestStatus.Approved) // If user is not null and operation is Approved
                    {
                        DeActivatedPreviousAllocation(req, selectedType);
                    }
                    string msg = string.Format("User Allocation record Successfully {0}", selectedType);
                    return(Json(new { Message = msg, MessageClass = MessageClass.Success, Response = true }));
                }
                else
                {
                    string msg = string.Format("User Allocation record not {0}", selectedType);
                    logger.InfoFormat("User Allocation record not {0}", selectedType);
                    return(Json(new { Message = msg, MessageClass = MessageClass.Error, Response = false }));
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace);
                return(Json(new { Message = Resources.Messages.MSG_GENERIC_DELETE_FAILED, MessageClass = MessageClass.Error, Response = false }));
            }
        }