public ActionResult FetchChangedIPs(RequestChangeIPViewModel 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 ChangeIp(RequestChangeIPViewModel viewmodel)
 {
     var customer = GetCurrentUserName();
     //Add request and log
     var result = RequestBLO.Current.AddRequestChangeIP(customer, viewmodel.RequestInfo.Description, viewmodel.SelectedServer, viewmodel.ReturningIPs);
     ////dang ky ham cho client
     Notify(result.NotificationCodes);
     return RedirectToAction("Detail", "Request", new
     { code = result.RefCode, msg = Constants.Message.SEND_REQUEST_CHANGE_IP });
 }
        public ActionResult Create(RequestCreateViewModel q)
        {
            var requestTypeCode = q.Type;
            if (!string.IsNullOrEmpty(requestTypeCode))
            {
                if (requestTypeCode == Constants.RequestTypeCode.ADD_SERVER)
                {
                    var data = new RequestAddServerViewModel();
                    data.Servers = new List<ServerExtendedModel>();
                    if (Session[Constants.Session.REQUEST_CODE] == null)
                    {
                        var requestCode = RequestBLO.Current.GenerateCode();
                        Session[Constants.Session.REQUEST_CODE] = requestCode;
                    }
                    var code = Session[Constants.Session.REQUEST_CODE].ToString();
                    data.ServerCount = code;
                    var serverInfos = TempRequestBLO.Current.GetByRequestCode(code);
                    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 >= 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");
                    }
                    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 customer = GetCurrentUserName();
                    var data = new RequestBringServerAwayViewModel();
                    //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)
                        {
                            if (q.RackCode != null)
                            {
                                var list = new List<ServerExtendedModel>();
                                foreach (var server in serverOfCustomer)
                                {
                                    server.Checked = true;
                                    list.Add(server);
                                }
                                data.ServerOfCustomer = list;
                                data.RackOfCustomer = rackOfCustomer
                                .Select(x => new SelectListItem { Value = x.RackCode, Text = x.RackName, Selected = x.RackCode == q.RackCode })
                                .ToList();
                            }
                            else
                            {
                                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 customer = GetCurrentUserName();
                    var data = new RequestAssignIPViewModel();
                    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 customer = GetCurrentUserName();
                    //co the change duoc nhieu IP--> bo sung t
                    var data = new RequestChangeIPViewModel();
                    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 customer = GetCurrentUserName();
                    var data = new RequestReturnIPViewModel();
                    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();
                    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 customer = GetCurrentUserName();
                    var data = new RequestReturnRackViewModel();
                    data.AllRacks = RackOfCustomerBLO.Current.CountServerPerRack(customer);
                    return View("ReturnRack", data);
                }
            }
            return RedirectToAction("Index", "Home");
        }
 public ActionResult ChangeIp(RequestChangeIPViewModel viewmodel)
 {
     var customer = GetCurrentUserName();
     if (!string.IsNullOrWhiteSpace(viewmodel.RequestInfo.Description))
     {
         viewmodel.RequestInfo.Description = viewmodel.RequestInfo.Description.Replace("\r\n", "<br/>");
     }
     else
     {
         viewmodel.RequestInfo.Description = Constants.Message.CONTENT_NULL;
     }
     //Add request and log
     var result = RequestBLO.Current.AddRequestChangeIP(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_CHANGE_IP });
 }