public JsonResult AddServerTemp(RequestAddServerViewModel data) { var result = new JsonResultModel(); result.Action = data.Server.btnAction; if (data.Server.btnAction == Constants.FormAction.EDIT_ACTION) { var temp = TempRequestBLO.Current.GetByKeys(new TempRequest { TempCode = data.Server.TempCode }); temp.Data = JsonConvert.SerializeObject(data.Server); TempRequestBLO.Current.Update(temp); result.Success = true; result.Codes.Add(temp.TempCode); } else { var temp = new TempRequest(); data.Server.Customer = GetCurrentUserName(); temp.RequestCode = Session[Constants.Session.REQUEST_CODE].ToString(); temp.Data = JsonConvert.SerializeObject(data.Server); temp.TempCode = TempRequestBLO.Current.GenerateCode(); TempRequestBLO.Current.Add(temp); result.Success = true; result.Codes.Add(temp.TempCode); } return Json(result); }
public ActionResult AddServer(RequestAddServerViewModel viewmodel) { var customer = GetCurrentUserName(); var requestCode = Session[Constants.Session.REQUEST_CODE].ToString(); //Add request and log var appointmentTime = viewmodel.RequestInfo.AppointmentTimeStr.ToDateTime("dd/MM/yyyy HH:mm"); var result = RequestBLO.Current.AddRequestAddServer(customer, viewmodel.RequestInfo.Description, appointmentTime, requestCode); //Xoa session server if (Session[Constants.Session.REQUEST_CODE] != null) { Session[Constants.Session.REQUEST_CODE] = null; } //dang ky ham cho client Notify(result.NotificationCodes); return RedirectToAction("Detail", "Request", new { code = requestCode, msg = Constants.Message.SEND_REQUEST_ADD_SERVER }); }
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 AddServer(RequestAddServerViewModel viewmodel) { var customer = GetCurrentUserName(); //Add request and log var appointmentTime = viewmodel.RequestInfo.AppointmentTimeStr.ToDateTime("dd/MM/yyyy HH:mm"); 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.AddRequestAddServer(customer, viewmodel.RequestInfo.Description, appointmentTime, viewmodel.rCode); //dang ky ham cho client Notify(result.NotificationCodes); return RedirectToAction("Detail", "Request", new { code = viewmodel.rCode, msg = Constants.Message.SEND_REQUEST_ADD_SERVER }); }