public ActionResult FetchReturnedIPs(RequestReturnIPViewModel model)
        {
            var currentIps = ServerIPBLO.Current.GetIPtoFetch(model.SelectedServer, Constants.StatusCode.SERVERIP_CURRENT);
            var newmodel   = model;

            newmodel.ServerIPs = currentIps;
            return(Json(newmodel, JsonRequestBehavior.AllowGet));
        }
        public ActionResult ReturnIp(RequestReturnIPViewModel viewmodel)
        {
            var customer = GetCurrentUserName();

            //Add and log request
            if (!string.IsNullOrWhiteSpace(viewmodel.RequestInfo.Description))
            {
                viewmodel.RequestInfo.Description = viewmodel.RequestInfo.Description.Replace("\r\n", "<br/>");
            }
            else
            {
                viewmodel.RequestInfo.Description = Constants.Message.CONTENT_NULL;
            }
            var result = RequestBLO.Current.AddRequestReturnIP(customer, viewmodel.RequestInfo.Description,
                                                               viewmodel.SelectedServer, viewmodel.ReturningIPs, viewmodel.rCode);

            //dang ky ham cho client
            Notify(result.NotificationCodes);
            return(RedirectToAction("Detail", "Request", new
                                    { code = result.RefCode, msg = Constants.Message.SEND_REQUEST_RETURN_IP }));
        }
        public ActionResult Create(string requestCode)
        {
            var customer     = GetCurrentUserName();
            var checkRequest = RequestBLO.Current.CheckExistedRequest(requestCode, customer);

            if (checkRequest)
            {
                var requestTypeCode = RequestBLO.Current.GetByKeys(new Request {
                    RequestCode = requestCode
                }).RequestType;
                if (requestTypeCode == Constants.RequestTypeCode.ADD_SERVER)
                {
                    var data = new RequestAddServerViewModel();
                    data.Servers     = new List <ServerExtendedModel>();
                    data.rCode       = requestCode;
                    data.ServerCount = requestCode;
                    var serverInfos = TempRequestBLO.Current.GetByRequestCode(requestCode);
                    foreach (var serverInfo in serverInfos)
                    {
                        var server = JsonConvert.DeserializeObject <ServerExtendedModel>(serverInfo.Data);
                        server.TempCode = serverInfo.TempCode;
                        data.Servers.Add(server);
                    }
                    data.RequestInfo = new RequestInfoModel();
                    var now = DateTime.Now;
                    if (now.Hour >= 16)
                    {
                        data.RequestInfo.AppointmentTimeStr = now.Date.AddHours(32).ToString("dd/MM/yyyy HH:mm");
                    }
                    else
                    {
                        var nextHour = now.Date.AddHours(now.Hour + 2);
                        data.RequestInfo.AppointmentTimeStr = nextHour.ToString("dd/MM/yyyy HH:mm");
                    }
                    data.ServerSizes = new int[] { 1, 2, 4 }
                    .Select(x => new SelectListItem {
                        Value = x.ToString(), Text = x.ToString()
                    })
                    .ToList();
                    return(View("AddServer", data));
                }
                if (requestTypeCode == Constants.RequestTypeCode.BRING_SERVER_AWAY)
                {
                    var data = new RequestBringServerAwayViewModel();
                    data.rCode = requestCode;
                    //lay server cua customer
                    var serverOfCustomer = ServerBLO.Current.GetServersOfCustomerByStatus(customer, Constants.StatusCode.SERVER_RUNNING);
                    if (serverOfCustomer.Count > 0)
                    {
                        //Muon hien thi number of server trong rack tuy theo viec lua chon dropdownlist
                        data.ServerNumber = serverOfCustomer.Count();
                        //rack cua server, select all va list cua rack, neu ko co thi ko hien
                        var rackOfCustomer = RackOfCustomerBLO.Current.GetRacksOfCustomer(customer,
                                                                                          Constants.StatusCode.RACKOFCUSTOMER_CURRENT);
                        if (rackOfCustomer.Count > 0)
                        {
                            data.ServerOfCustomer = serverOfCustomer;
                            data.RackOfCustomer   = rackOfCustomer
                                                    .Select(x => new SelectListItem {
                                Value = x.RackCode, Text = x.RackName
                            })
                                                    .ToList();
                        }
                        else
                        {
                            data.ServerOfCustomer = serverOfCustomer;
                        }
                        data.RequestInfo = new RequestInfoModel();
                        var now = DateTime.Now;
                        if (now.Hour >= 20)
                        {
                            data.RequestInfo.AppointmentTimeStr = now.Date.AddHours(32).ToString("dd/MM/yyyy HH:mm");
                        }
                        else
                        {
                            data.RequestInfo.AppointmentTimeStr = now.Date.AddHours(10).ToString("dd/MM/yyyy HH:mm");
                        }
                    }
                    return(View("BringServerAway", data));
                }
                else if (requestTypeCode == Constants.RequestTypeCode.ASSIGN_IP)
                {
                    var data = new RequestAssignIPViewModel();
                    data.rCode = requestCode;
                    var listNumbers = new List <string>();
                    for (var i = 1; i < 11; i++)
                    {
                        listNumbers.Add(i.ToString());
                    }
                    data.NumberOfIPOptions = listNumbers
                                             .Select(x => new SelectListItem {
                        Value = x, Text = x
                    })
                                             .ToList();
                    var listServers = ServerBLO.Current.GetServersOfCustomerByStatus(customer, Constants.StatusCode.SERVER_RUNNING);
                    data.ServerOptions = listServers
                                         .Select(x => new SelectListItem {
                        Value = x.ServerCode, Text = x.ServerDefaultIP
                    })
                                         .ToList();
                    return(View("AssignIP", data));
                }
                else if (requestTypeCode == Constants.RequestTypeCode.CHANGE_IP)
                {
                    var data = new RequestChangeIPViewModel();
                    data.rCode = requestCode;
                    var listServers = ServerBLO.Current.GetServersOfCustomerByStatus(customer, Constants.StatusCode.SERVER_RUNNING);
                    data.ServerOptions = listServers
                                         .Select(x => new SelectListItem {
                        Value = x.ServerCode, Text = x.ServerDefaultIP
                    })
                                         .ToList();
                    return(View("ChangeIP", data));
                }
                else if (requestTypeCode == Constants.RequestTypeCode.RETURN_IP)
                {
                    var data = new RequestReturnIPViewModel();
                    data.rCode = requestCode;
                    var listServers = ServerBLO.Current.GetServersOfCustomerByStatus(customer, Constants.StatusCode.SERVER_RUNNING);
                    data.ServerOptions = listServers
                                         .Select(x => new SelectListItem {
                        Value = x.ServerCode, Text = x.ServerDefaultIP
                    })
                                         .ToList();
                    return(View("ReturnIP", data));
                }
                else if (requestTypeCode == Constants.RequestTypeCode.RENT_RACK)
                {
                    var data = new RequestRentRackViewModel();
                    data.rCode = requestCode;
                    var myList = new List <SelectListItem>();
                    for (var i = 0; i < 10; i++)
                    {
                        var num  = (i + 1).ToString();
                        var item = new SelectListItem()
                        {
                            Value = num,
                            Text  = num
                        };
                        myList.Add(item);
                    }
                    data.ListRackNumbers = myList;
                    return(View("RentRack", data));
                }
                else if (requestTypeCode == Constants.RequestTypeCode.RETURN_RACK)
                {
                    var data = new RequestReturnRackViewModel();
                    data.rCode    = requestCode;
                    data.AllRacks = RackOfCustomerBLO.Current.CountServerPerRack(customer);
                    return(View("ReturnRack", data));
                }
            }
            return(RedirectToAction("Index", "Error"));
        }