public ActionResult CancelRequestBringServerAway(ProcessRequestBringServerAwayViewModel viewmodel)
 {
     var customer = GetCurrentUserName();
     //Update lai serverip, server, request
     var result = RequestBLO.Current.CancelRequestBringServerAway(viewmodel.RequestInfo.RequestCode,
         customer, viewmodel.RequestInfo.TaskCode);
     //dang ky ham cho client
     Notify(result.NotificationCodes);
     return RedirectToAction("Detail", "Request", new
     { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.CANCEL_REQUEST_BRING_SERVER_AWAY });
 }
 public ActionResult ProcessRequestBringServerAway(ProcessRequestBringServerAwayViewModel viewmodel)
 {
     var status = RequestBLO.Current.GetByKeys(new Request { RequestCode = viewmodel.RequestInfo.RequestCode }).StatusCode;
     if (status == Constants.StatusCode.REQUEST_REJECTED || status == Constants.StatusCode.REQUEST_DONE || status == Constants.StatusCode.REQUEST_CANCELLED)
     {
         return RedirectToAction("Detail", "ProcessRequest", new
         {
             code = viewmodel.RequestInfo.RequestCode,
             msg = Constants.Message.ERROR_CANCEL_REQUEST
         });
     }
     else
     {
         //assign pending
         if (Request.Form[Constants.FormAction.ACCEPT_ACTION] != null)
         {
             if (status == Constants.StatusCode.REQUEST_PENDING)
             {
                 var shifthead = GetCurrentUserName();
                 var result = RequestBLO.Current.AcceptRequest(viewmodel.RequestInfo.RequestCode, shifthead,
                    viewmodel.RequestInfo.Assignee, Constants.StatusCode.REQUEST_WAITING,
                    Constants.TypeOfLog.LOG_BRING_SERVER_AWAY, true);
                 //dang ky ham cho client
                 Notify(result.NotificationCodes);
                 return RedirectToAction("Detail", "ProcessRequest",
                     new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.ACCEPT_REQUEST_BRING_SERVER_AWAY });
             }
             else
             {
                 return RedirectToAction("Detail", "ProcessRequest", new
                 {
                     code = viewmodel.RequestInfo.RequestCode,
                     msg = Constants.Message.ERROR_CANCEL_REQUEST
                 });
             }
         }
         if (Request.Form[Constants.FormAction.APPROVE_ACTION] != null)
         {
             var assignee = RequestBLO.Current.GetByKeys(new Request { RequestCode = viewmodel.RequestInfo.RequestCode }).Assignee;
             if (assignee == viewmodel.RequestInfo.Assignee)
             {
                 var result = RequestBLO.Current.ApproveRequestBringServerAway(viewmodel.RequestInfo.RequestCode, viewmodel.ServerOfCustomer,
                 viewmodel.RequestInfo.Assignee, viewmodel.RequestInfo.TaskCode);
                 //dang ky ham cho client
                 Notify(result.NotificationCodes);
                 return RedirectToAction("Detail", "ProcessRequest",
                     new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.APPROVE_REQUEST_BRING_SERVER_AWAY });
             }
             else
             {
                 return RedirectToAction("Detail", "ProcessRequest", new
                 {
                     code = viewmodel.RequestInfo.RequestCode,
                     msg = "Error! You are not authorized."
                 });
             }
         }
         if (Request.Form[Constants.FormAction.REJECT_ACTION] != null)
         {
             var assignee = RequestBLO.Current.GetByKeys(new Request { RequestCode = viewmodel.RequestInfo.RequestCode }).Assignee;
             if (assignee == null)
             {
                 assignee = GetCurrentUserName();
             }
             if (assignee == viewmodel.RequestInfo.Assignee)
             {
                 var result = RequestBLO.Current.RejectRequestAssignIP(viewmodel.RequestInfo.RequestCode,
                     assignee, viewmodel.RequestInfo.TaskCode, viewmodel.RequestInfo.Reason);
                 //dang ky ham cho client
                 Notify(result.NotificationCodes);
                 return RedirectToAction("Detail", "ProcessRequest",
                     new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.REJECT_REQUEST_BRING_SERVER_AWAY });
             }
             else
             {
                 return RedirectToAction("Detail", "ProcessRequest", new
                 {
                     code = viewmodel.RequestInfo.RequestCode,
                     msg = "Error! You are not authorized."
                 });
             }
         }
         if (Request.Form[Constants.FormAction.PROCESS_ACTION] != null)
         {
             var shifthead = GetCurrentUserName();
             RequestBLO.Current.AcceptRequest(viewmodel.RequestInfo.RequestCode, shifthead,
                viewmodel.RequestInfo.Assignee, Constants.StatusCode.REQUEST_PROCESSING,
                Constants.TypeOfLog.LOG_BRING_SERVER_AWAY, false);
             var task = RequestBLO.Current.AssignTask(viewmodel.RequestInfo.RequestCode, shifthead,
                 viewmodel.RequestInfo.Assignee);
             //dang ky ham cho client
             if (viewmodel.RequestInfo.Assignee != shifthead)
             {
                 Notify(task.NotificationCodes);
             }
             return RedirectToAction("Detail", "ProcessRequest",
                 new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.PROCESSING_REQUEST_BRING_SERVER_AWAY });
         }
         if (Request.Form[Constants.FormAction.REASSIGN_ACTION] != null)
         {
             var shifthead = GetCurrentUserName();
             var check = RequestBLO.Current.IsShiftHeadDoingTask(viewmodel.RequestInfo.TaskCode);
             var taskstatus = TaskBLO.Current.GetByKeys(new Task { TaskCode = viewmodel.RequestInfo.TaskCode }).StatusCode;
             if (taskstatus == Constants.StatusCode.TASK_WAITING || taskstatus == Constants.StatusCode.TASK_NOTFINISH || check)
             {
                 if (viewmodel.RequestInfo.TaskStatus != Constants.StatusCode.TASK_NOTFINISH)
                 {
                     var preTask = RequestBLO.Current.CancelTask(viewmodel.RequestInfo.TaskCode,
                     viewmodel.RequestInfo.RequestCode, viewmodel.RequestInfo.Assignee, shifthead);
                     //dang ky ham cho client
                     if (viewmodel.RequestInfo.Assignee != shifthead)
                     {
                         Notify(preTask.NotificationCodes);
                     }
                 }
                 var newTask = RequestBLO.Current.ReAssignTask(viewmodel.RequestInfo.TaskCode, viewmodel.RequestInfo.RequestCode,
                     viewmodel.RequestInfo.Assignee, viewmodel.RequestInfo.AssignedStaff, shifthead);
                 //dang ky ham cho client
                 if (viewmodel.RequestInfo.AssignedStaff != shifthead)
                 {
                     Notify(newTask.NotificationCodes);
                 }
                 var message = Constants.Message.REASSIGN_TASK + viewmodel.RequestInfo.AssignedStaffName;
                 return RedirectToAction("Detail", "ProcessRequest",
                     new { code = viewmodel.RequestInfo.RequestCode, msg = message });
             }
             else
             {
                 return RedirectToAction("Detail", "ProcessRequest", new
                 {
                     code = viewmodel.RequestInfo.RequestCode,
                     msg = "Error! Staff is processing request."
                 });
             }
         }
         if (Request.Form[Constants.FormAction.ACCEPT_TASK_ACTION] != null)
         {
             var taskstatus = TaskBLO.Current.GetByKeys(new Task { TaskCode = viewmodel.RequestInfo.TaskCode }).StatusCode;
             if (taskstatus == Constants.StatusCode.TASK_WAITING)
             {
                 //update task
                 TaskBLO.Current.UpdateTaskStatus(viewmodel.RequestInfo.TaskCode, Constants.StatusCode.TASK_DOING);
                 return RedirectToAction("Detail", "ProcessRequest",
                     new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.ACCEPT_TASK });
             }
             else
             {
                 return RedirectToAction("Detail", "ProcessRequest", new
                 {
                     code = viewmodel.RequestInfo.RequestCode,
                     msg = "Error! Your task is cancelled."
                 });
             }
         }
         if (Request.Form[Constants.FormAction.NOT_FINISHED_TASK_ACTION] != null)
         {
             var result = RequestBLO.Current.NotFinishRequest(viewmodel.RequestInfo.TaskCode, viewmodel.RequestInfo.NotFinishReason);
             Notify(result.NotificationCodes);
             return RedirectToAction("Detail", "ProcessRequest",
                new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.NOT_FINISHED_TASK });
         }
     }
     return RedirectToAction("Index");
 }
 public ActionResult ProcessRequestBringServerAway(ProcessRequestBringServerAwayViewModel viewmodel)
 {
     //assign pending
     if (Request.Form[Constants.FormAction.ACCEPT_ACTION] != null)
     {
         var shifthead = GetCurrentUserName();
         var result = RequestBLO.Current.AcceptRequest(viewmodel.RequestInfo.RequestCode, shifthead,
            viewmodel.RequestInfo.Assignee, Constants.StatusCode.REQUEST_WAITING,
            Constants.TypeOfLog.LOG_BRING_SERVER_AWAY, true);
         //dang ky ham cho client
         Notify(result.NotificationCodes);
         return RedirectToAction("Detail", "ProcessRequest",
             new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.ACCEPT_REQUEST_BRING_SERVER_AWAY });
     }
     if (Request.Form[Constants.FormAction.APPROVE_ACTION] != null)
     {
         var result = RequestBLO.Current.ApproveRequestBringServerAway(viewmodel.RequestInfo.RequestCode, viewmodel.ServerOfCustomer,
             viewmodel.RequestInfo.Assignee, viewmodel.RequestInfo.TaskCode);
         //dang ky ham cho client
         Notify(result.NotificationCodes);
         return RedirectToAction("Detail", "ProcessRequest",
             new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.APPROVE_REQUEST_BRING_SERVER_AWAY });
     }
     if (Request.Form[Constants.FormAction.REJECT_ACTION] != null)
     {
         var assignee = viewmodel.RequestInfo.Assignee;
         if (viewmodel.RequestInfo.Assignee == null)
         {
             assignee = GetCurrentUserName();
         }
         var result = RequestBLO.Current.RejectRequestBringServerAway(viewmodel.RequestInfo.RequestCode, viewmodel.ServerOfCustomer,
             assignee, viewmodel.RequestInfo.TaskCode, viewmodel.RequestInfo.Reason);
         //dang ky ham cho client
         Notify(result.NotificationCodes);
         return RedirectToAction("Detail", "ProcessRequest",
             new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.REJECT_REQUEST_BRING_SERVER_AWAY });
     }
     if (Request.Form[Constants.FormAction.PROCESS_ACTION] != null)
     {
         var shifthead = GetCurrentUserName();
         RequestBLO.Current.AcceptRequest(viewmodel.RequestInfo.RequestCode, shifthead,
            viewmodel.RequestInfo.Assignee, Constants.StatusCode.REQUEST_PROCESSING,
            Constants.TypeOfLog.LOG_BRING_SERVER_AWAY, false);
         var task = RequestBLO.Current.AssignTask(viewmodel.RequestInfo.RequestCode, shifthead,
             viewmodel.RequestInfo.Assignee);
         //dang ky ham cho client
         if (viewmodel.RequestInfo.Assignee != shifthead)
         {
             Notify(task.NotificationCodes);
         }
         return RedirectToAction("Detail", "ProcessRequest",
             new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.PROCESSING_REQUEST_BRING_SERVER_AWAY });
     }
     if (Request.Form[Constants.FormAction.REASSIGN_ACTION] != null)
     {
         var shifthead = GetCurrentUserName();
         if (viewmodel.RequestInfo.TaskStatus != Constants.StatusCode.TASK_NOTFINISH)
         {
             var preTask = RequestBLO.Current.CancelTask(viewmodel.RequestInfo.TaskCode,
             viewmodel.RequestInfo.RequestCode, viewmodel.RequestInfo.Assignee, shifthead);
             //dang ky ham cho client
             if (viewmodel.RequestInfo.Assignee != shifthead)
             {
                 Notify(preTask.NotificationCodes);
             }
         }
         var newTask = RequestBLO.Current.ReAssignTask(viewmodel.RequestInfo.TaskCode, viewmodel.RequestInfo.RequestCode,
             viewmodel.RequestInfo.Assignee, viewmodel.RequestInfo.AssignedStaff, shifthead);
         //dang ky ham cho client
         if (viewmodel.RequestInfo.AssignedStaff != shifthead)
         {
             Notify(newTask.NotificationCodes);
         }
         var message = Constants.Message.REASSIGN_TASK + viewmodel.RequestInfo.AssignedStaffName;
         return RedirectToAction("Detail", "ProcessRequest",
             new { code = viewmodel.RequestInfo.RequestCode, msg = message });
     }
     if (Request.Form[Constants.FormAction.ACCEPT_TASK_ACTION] != null)
     {
         //update task
         TaskBLO.Current.UpdateTaskStatus(viewmodel.RequestInfo.TaskCode, Constants.StatusCode.TASK_DOING);
         return RedirectToAction("Detail", "ProcessRequest",
             new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.ACCEPT_TASK });
     }
     if (Request.Form[Constants.FormAction.NOT_FINISHED_TASK_ACTION] != null)
     {
         var result = RequestBLO.Current.NotFinishRequest(viewmodel.RequestInfo.TaskCode, viewmodel.RequestInfo.NotFinishReason);
         Notify(result.NotificationCodes);
         return RedirectToAction("Detail", "ProcessRequest",
            new { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.NOT_FINISHED_TASK });
     }
     return RedirectToAction("Index");
 }
 public ActionResult CancelRequestBringServerAway(ProcessRequestBringServerAwayViewModel viewmodel)
 {
     var status = RequestBLO.Current.GetByKeys(new Request { RequestCode = viewmodel.RequestInfo.RequestCode }).StatusCode;
     if (status == Constants.StatusCode.REQUEST_REJECTED || status == Constants.StatusCode.REQUEST_DONE || status == Constants.StatusCode.REQUEST_CANCELLED)
     {
         return RedirectToAction("Detail", "Request", new
         {
             code = viewmodel.RequestInfo.RequestCode,
             msg = Constants.Message.ERROR_CANCEL_REQUEST
         });
     }
     else
     {
         var customer = GetCurrentUserName();
         //Update lai serverip, server, request
         var result = RequestBLO.Current.CancelRequestBringServerAway(viewmodel.RequestInfo.RequestCode,
             customer, viewmodel.RequestInfo.TaskCode);
         //dang ky ham cho client
         Notify(result.NotificationCodes);
         return RedirectToAction("Detail", "Request", new
         { code = viewmodel.RequestInfo.RequestCode, msg = Constants.Message.CANCEL_REQUEST_BRING_SERVER_AWAY });
     }
 }