public ActionResult CreateEdit(CrewViewModel model) { try { if (ModelState.IsValid) { if (CrewDataAccess.Update(model)) { return(Json(new { success = true, Message = "Success" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, Message = CrewDataAccess.Message }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { success = false, Message = "Please complete all required field" }, JsonRequestBehavior.AllowGet)); } } catch (Exception Ex) { return(Json(new { success = false, Message = Ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetCrewSchedule(int StaffID) { CrewViewModel crewVM = new CrewViewModel(); crewVM.flightCrewList = crewContext.GetFlightCrew(StaffID); return(View(crewVM)); }
public ActionResult _GetCrews(int conveyanceInOutId, bool isCrew) { //สองตัวนี้ไม่ได้ใช้ ส่งไปให้ครบเท่านั้น string cName = ""; var ioDate = DateTime.Today; //th20110411 vvv เพิ่ม addRemoveCrews เพื่อดึงไป show ในหน้าคนเรือด้วย PD18-540102 Req 8 IList <AddRemoveCrew> addRemoveCrews = null; if (isCrew) { var convInout = convInOutRepo.GetOne(conveyanceInOutId); if (convInout != null) { if (convInout.InOutType == ModelConst.CONVINOUT_OUT) //เอาเฉพาะกรณีออกเท่านั้น { addRemoveCrews = convInout.DiffCrew; } } } //th20440411 ^^^ var esvm = new CrewViewModel(conveyanceInOutId, isCrew, cName, ioDate, crewRepo.FindAll(conveyanceInOutId, isCrew).ToList(), addRemoveCrews); //th20110411 return(View(new GridModel(esvm.vmCrews))); }
public IActionResult Index() { var model = new CrewViewModel { Title = _localizer["Crew.Title"] }; return(View(model)); }
public void CreateCrews(CrewViewModel model) { var crew = new ScheduleCrew() { CrewID = model.CrewID, ScheduleID = model.ScheduleID }; _context.Add <ScheduleCrew>(crew); _context.SaveChanges(); }
// GET: Crew/Create public IActionResult Create() { //create Crew object to provide data for dropdown list form values var crewCreate = new CrewViewModel(); //Message string to be used by Index View string msg = "Please input house number/name and post code."; ViewBag.msg = msg; return(View(crewCreate)); }
public IHttpActionResult PostCrew(CrewViewModel crew) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } repository.UpdateCrew(crew.MapTo <Crew>()); return(Ok(crew)); }
public ActionResult CreateCrew(int id, string code, string date) { var viewModel = new CrewViewModel { FlightId = id, FlightCode = code, CrewMembers = _crewService.GetFreeCrewMembers(id, date) }; return(View("CrewForm", viewModel)); }
public ActionResult CreateCrew(CrewViewModel viewModel) { if (!ModelState.IsValid) { viewModel.CrewMembers = _crewService.GetFreeCrewMembers(viewModel.FlightId, viewModel.Date); return(View("CrewForm", viewModel)); } _crewService.CreateCrew(viewModel); return(RedirectToAction("ShowCrews", "Dispatcher")); }
public ActionResult UpdateCrew(int id, string date) { var viewModel = new CrewViewModel() { CrewMembers = _crewService.GetFreeCrewMembers(id, date) }; viewModel = _crewService.FormCrew(id, viewModel); return(View("CrewForm", viewModel)); }
public static bool Update(CrewViewModel model) { bool result = true; try { using (var db = new FleetManagementContext()) { if (model.Id == 0) { MstCrew crw = new MstCrew(); crw.CrewId = model.CrewId; crw.CrewName = model.CrewName; crw.DrivingLicenseNumber = model.DrivingLicenseNumber; crw.Address = model.Address; crw.PlaceOfBirth = model.PlaceOfBirth; crw.DateOfBirth = model.DateOfBirth; crw.Gender = model.Gender; crw.Role = model.Role; crw.IsActive = model.IsActive; db.MstCrews.Add(crw); db.SaveChanges(); } else { MstCrew crw = db.MstCrews.Where(o => o.Id == model.Id).FirstOrDefault(); if (crw != null) { crw.CrewId = model.CrewId; crw.CrewName = model.CrewName; crw.DrivingLicenseNumber = model.DrivingLicenseNumber; crw.Address = model.Address; crw.PlaceOfBirth = model.PlaceOfBirth; crw.DateOfBirth = model.DateOfBirth; crw.Gender = model.Gender; crw.Role = model.Role; crw.IsActive = model.IsActive; db.SaveChanges(); } } } } catch (Exception Ex) { Message = Ex.Message; result = false; } return(result); }
public void CreateCrew(CrewViewModel viewModel) { var flight = _unitOfWork.Flights.GetFlight(viewModel.FlightId); _unitOfWork.CrewMembers.CreateCrew(flight, new List <int>() { viewModel.Captain, viewModel.FirstPilot, viewModel.Navigator, viewModel.RadioOperator, viewModel.MainFlightAttendant, viewModel.FligthAttendant }); _unitOfWork.Complete(); }
public IHttpActionResult PutCrew(int id, CrewViewModel crew) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != crew.Id) { return(BadRequest()); } repository.UpdateCrew(crew.MapTo <Crew>()); return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult Search(string name, int pageIndex, int pageSize) { string shipId = base.user.ShipId; var datacrew = _context.Crew.Where(c => string.IsNullOrEmpty(name) ? 1 == 1 : c.Name.Contains(name)).ToList(); int count = datacrew.Count(); var data = datacrew.Skip((pageIndex - 1) * pageSize).Take(pageSize); var Pics = _context.CrewPicture.ToList(); crewVMList = new List <CrewViewModel>(); foreach (var item in data) { CrewViewModel model = new CrewViewModel() { Id = item.Id, Job = item.Job, Name = item.Name, crewPictureViewModels = new List <CrewPictureViewModel>() }; var picW = Pics.Where(c => c.CrewId == item.Id); foreach (var pic in picW) { CrewPictureViewModel vmpic = new CrewPictureViewModel() { Id = pic.Id, Picture = Convert.ToBase64String(pic.Picture) }; model.crewPictureViewModels.Add(vmpic); } crewVMList.Add(model); } var result = new { code = 0, data = crewVMList, count = count, pageIndex = pageIndex, pageSize = pageSize, isSet = !string.IsNullOrEmpty(shipId) ? base.user.EnableConfigure : false }; return(new JsonResult(result)); }
public CrewViewModel FormCrew(int id, CrewViewModel viewModel) { var flight = _unitOfWork.Flights.GetFlight(id); viewModel.FlightId = flight.FlightId; viewModel.Date = flight.Date.ToString("dd/MM/yyyy"); viewModel.FlightCode = flight.Code; foreach (var member in flight.CrewMembers) { switch (member.CrewMember.ProfessionId) { case 1: viewModel.Captain = member.CrewMemberId; break; case 2: viewModel.FirstPilot = member.CrewMemberId; break; case 3: viewModel.Navigator = member.CrewMemberId; break; case 4: viewModel.RadioOperator = member.CrewMemberId; break; case 5: viewModel.MainFlightAttendant = member.CrewMemberId; break; case 6: viewModel.FligthAttendant = member.CrewMemberId; break; } } return(viewModel); }
public void UpdateCrew(CrewViewModel viewModel) { var crew = _unitOfWork.Flights.FindCrew(viewModel.FlightId); foreach (var cr in crew) { cr.FlightId = viewModel.FlightId; switch (cr.CrewMember.ProfessionId) { case 1: cr.CrewMemberId = viewModel.Captain; break; case 2: cr.CrewMemberId = viewModel.FirstPilot; break; case 3: cr.CrewMemberId = viewModel.Navigator; break; case 4: cr.CrewMemberId = viewModel.RadioOperator; break; case 5: cr.CrewMemberId = viewModel.MainFlightAttendant; break; case 6: cr.CrewMemberId = viewModel.FligthAttendant; break; } } _unitOfWork.Complete(); }
public static CrewViewModel GetById(int id) { CrewViewModel result = new CrewViewModel(); using (var db = new FleetManagementContext()) { result = (from crw in db.MstCrews where crw.Id == id select new CrewViewModel { Id = crw.Id, CrewId = crw.CrewId, CrewName = crw.CrewName, DrivingLicenseNumber = crw.DrivingLicenseNumber, Address = crw.Address, PlaceOfBirth = crw.PlaceOfBirth, DateOfBirth = crw.DateOfBirth, Gender = crw.Gender, Role = crw.Role, IsActive = crw.IsActive }).FirstOrDefault(); } return(result); }
public CrewListView() { this.InitializeComponent(); ViewModel = new CrewViewModel(); }
public CrewView() { CrewViewModel = new CrewViewModel(); this.InitializeComponent(); }
//public IActionResult Create(string postcode, string HouseNo, string Name, string Type, string Email, string MobNo, DateTime DateOfBirth) public IActionResult Create(CrewViewModel FullAddress, string click) //instantiate CrewViewModel object to store form values { //if (click.Equals("Find")) //{ //Use plugin Net.Http to connect to API, create new object using (HttpClient client = new HttpClient()) { //Store any populated form values in model object called FullAddress, required as View reloads page and input values get blanked string Name = FullAddress.Name; DateTime DateOfBirth = FullAddress.DateOfBirth; string postcode = FullAddress.postcode; //required for address lookup below string HouseNo = FullAddress.HouseNo; //required for address lookup below string Email = FullAddress.Email; string MobNo = FullAddress.MobNo; int CrewId = FullAddress.CrewId; string Type = FullAddress.Type; //Connection details for GetAddress.io API that returns full addresses when House No/Name & Postcode provided string apiKey = "3zQi9kpO6E6icIxK75pDxQ11165"; string website = "https://api.getaddress.io/find/" + postcode + "/" + HouseNo + "?api-key=" + apiKey; client.BaseAddress = new Uri(website); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync("").Result; //If API successfully returns address run following if if (response.IsSuccessStatusCode) { //create object with API JSON response value var AddressResponse = response.Content.ReadAsStringAsync().Result; //Use Newtonsoft JSON plugin to deserialize response var JSONaddress = JsonConvert.DeserializeObject <CrewViewModel>(AddressResponse); //GetAddress() API always returns address values as an array with each address line being comma spearated values. //As we're only looking for singular addresses we always use the first and only value in the return array and assign it to a string. string fullAddress = JSONaddress.addresses[0]; //Separate address string into an array using comma separator to identify values, also removes any white space. string[] values = fullAddress.Split(',').Select(sValue => sValue.Trim()).ToArray(); //Assign array values to associated strings string AddressLine1 = values[0]; string AddressLine2 = values[1]; string AddressLine3 = values[2]; string AddressLine4 = values[3]; string Locality = values[4]; string TownOrCity = values[5]; string County = values[6]; //Create array of the strings string[] myStrings = new string[] { AddressLine1, AddressLine2, AddressLine3, AddressLine4, Locality, TownOrCity, County, postcode, null }; //Build full address string from populated (not empty/null) values adding line break between each line //JSONaddress.formattedAddress = string.Join(System.Environment.NewLine, myStrings.Where(str => !string.IsNullOrEmpty(str))); JSONaddress.formattedAddress = string.Join(", ", myStrings.Where(str => !string.IsNullOrEmpty(str))); if (JSONaddress.formattedAddress != null) { //store formattedAddress string in Address field in model object FullAddress.Address = JSONaddress.formattedAddress; //Store values to TempData for usage in the CreateRecord action method TempData["Name"] = FullAddress.Name; TempData["DateOfBirth"] = FullAddress.DateOfBirth; TempData["Address"] = FullAddress.Address; TempData["MobNo"] = FullAddress.MobNo; TempData["Email"] = FullAddress.Email; TempData["CrewId"] = FullAddress.CrewId; TempData["Type"] = FullAddress.Type; // return(View("CreateRecord", FullAddress)); } } //If address not found send following message to View string msg = "Address not found, please try again."; ViewBag.NoAddress = "No Address"; ViewBag.msg = msg; return(View("Create", FullAddress)); } }
public IActionResult CreateRecord(CrewViewModel FullAddress) { return(View(FullAddress)); }
public string Create(CalendarViewModel model) { string msg = string.Empty; try { int id = 0; var schedule = new Schedule() { Name = model.Title, AircraftID = model.AircraftID, RegistrationID = model.RegistrationID, StartDate = DateTime.Parse(model.Start), EndDate = DateTime.Parse(model.End), RouteStartID = model.RouteStartID, RouteDestinationID = model.DestinationID, RouteEndID = model.RouteEndID, PilotID = model.PilotID, AssistantPilotID = model.CopilotID, Notes = model.Notes, Passengers = model.Passengers, FlightInfo = model.FlightInfo, TechnicalStops = model.TechnicalStops, ETC = model.ETC, WaitingStart = DateTime.Parse(model.WaitingStart), WaitingEnd = DateTime.Parse(model.WaitingEnd) }; _context.Add <Schedule>(schedule); _context.SaveChanges(); id = schedule.ID; #region Create Crew data if (id > 0) { string crewids = model.CrewIDs.Remove(model.CrewIDs.Length - 1); string[] ids = crewids.Split(','); foreach (var crewid in ids) { if (!string.IsNullOrEmpty(crewid)) { CrewViewModel crewmodel = new CrewViewModel() { CrewID = Convert.ToInt32(crewid), ScheduleID = id }; this.CreateCrews(crewmodel); } } } #endregion #region Log Create string fullname = string.Empty; var user = _userService.GetAll().Where(x => x.ID == model.LoggedUserID).FirstOrDefault(); if (user != null) { fullname = string.Format("{0}, {1}", user.LastName, user.FirstName); LogsViewModel log = new LogsViewModel() { ActionType = ActionType.DataModification.ToString(), Description = string.Format("New Schedule Created. <br /> ScheduleID:{0} <br /> LoggedUserID: {1}", id, user.ID), ModifiedBy = fullname, DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm") }; new LogsService().Create(log); } #endregion msg = "Schedule added."; } catch (Exception ex) { LogsViewModel error = new LogsViewModel() { ActionType = ActionType.Error.ToString(), Description = ex.Message + "\n" + ex.StackTrace, ModifiedBy = "Calendar Service Error : Create()", DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm") }; new LogsService().Create(error); msg = "Unexpected error encountered. Please contact your system administrator."; } return(msg); }
public string Update(CalendarViewModel model) { string msg = string.Empty; try { #region Update Calendar Schedule var calendar = _context.AsQueryable <Schedule>().Where(x => x.ID == model.ID).FirstOrDefault(); if (calendar != null) { if (model.IsChangeSchedOnly == false) { if (!string.IsNullOrEmpty(model.Title)) { calendar.Name = model.Title; } if (model.AircraftID > 0) { calendar.AircraftID = model.AircraftID; } if (model.RegistrationID > 0) { calendar.RegistrationID = model.RegistrationID; } if (!string.IsNullOrEmpty(model.Start)) { calendar.StartDate = DateTime.Parse(model.Start); } if (!string.IsNullOrEmpty(model.End)) { calendar.EndDate = DateTime.Parse(model.End); } if (model.RouteStartID > 0) { calendar.RouteStartID = model.RouteStartID; } if (model.DestinationID > 0) { calendar.RouteDestinationID = model.DestinationID; } if (model.RouteEndID > 0) { calendar.RouteEndID = model.RouteEndID; } if (model.PilotID > 0) { calendar.PilotID = model.PilotID; } if (model.CopilotID > 0) { calendar.AssistantPilotID = model.CopilotID; } if (!string.IsNullOrEmpty(model.Notes)) { calendar.Notes = model.Notes; } if (!string.IsNullOrEmpty(model.Passengers)) { calendar.Passengers = model.Passengers; } if (!string.IsNullOrEmpty(model.FlightInfo)) { calendar.FlightInfo = model.FlightInfo; } if (!string.IsNullOrEmpty(model.TechnicalStops)) { calendar.TechnicalStops = model.TechnicalStops; } if (!string.IsNullOrEmpty(model.ETC)) { calendar.ETC = model.ETC; } if (!string.IsNullOrEmpty(model.WaitingStart)) { calendar.WaitingStart = DateTime.Parse(model.WaitingStart); } if (!string.IsNullOrEmpty(model.WaitingEnd)) { calendar.WaitingEnd = DateTime.Parse(model.WaitingEnd); } _context.Update(calendar); _context.SaveChanges(); #region Update Crew //delete crew first this.DeleteCrewBySchedule(calendar.ID, model.LoggedUserID); string crewids = model.CrewIDs.Remove(model.CrewIDs.Length - 1); string[] ids = crewids.Split(','); foreach (var crewid in ids) { if (!string.IsNullOrEmpty(crewid)) { CrewViewModel crewmodel = new CrewViewModel() { CrewID = Convert.ToInt32(crewid), ScheduleID = calendar.ID }; this.CreateCrews(crewmodel); } } #endregion } else { //change sched only string newStart = "", newEnd = "", updatedEnd = "", newStart2 = "", updatedStart2 = "", newEnd2 = "", updatedEnd2 = ""; newStart = DateTime.Parse(model.Start).ToString("yyyy-MM-dd HH:mm"); newEnd = DateTime.Parse(calendar.EndDate.ToString()).ToString("yyyy-MM-dd HH:mm"); newStart2 = DateTime.Parse(calendar.WaitingStart.ToString()).ToString("yyyy-MM-dd HH:mm"); newEnd2 = DateTime.Parse(calendar.WaitingEnd.ToString()).ToString("yyyy-MM-dd HH:mm"); #region Get diffrence double diff1 = 0; diff1 = calendar.StartDate.Date.Subtract(calendar.EndDate).Days; //((DateTime)calendar.WaitingEnd).Date.Subtract( calendar.StartDate.Date ).Days; #endregion if (diff1 > 0) { updatedEnd = DateTime.Parse(newStart).AddDays(diff1).ToString("yyyy-MM-dd HH:mm").Substring(0, 10) + newEnd.Substring(10); } else { updatedEnd = newStart.Substring(0, 10) + newEnd.Substring(10); } updatedStart2 = newStart.Substring(0, 10) + newStart2.Substring(10); updatedEnd2 = newEnd2.Substring(0, 10) + newEnd2.Substring(10); calendar.StartDate = DateTime.Parse(model.Start); calendar.EndDate = DateTime.Parse(updatedEnd); calendar.WaitingStart = DateTime.Parse(updatedStart2); calendar.WaitingEnd = DateTime.Parse(updatedEnd2); _context.Update(calendar); _context.SaveChanges(); } msg = "Schedule updated."; } #endregion #region Log Create string fullname = string.Empty; var user = _userService.GetAll().Where(x => x.ID == model.LoggedUserID).FirstOrDefault(); if (user != null) { fullname = string.Format("{0}, {1}", user.LastName, user.FirstName); LogsViewModel log = new LogsViewModel() { ActionType = ActionType.DataModification.ToString(), Description = string.Format("Schedule Updated. <br /> ScheduleID:{0} <br /> LoggedUserID: {1}", model.ID, user.ID), ModifiedBy = fullname, DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm") }; new LogsService().Create(log); } #endregion } catch (Exception ex) { LogsViewModel error = new LogsViewModel() { ActionType = ActionType.Error.ToString(), Description = ex.Message + "\n" + ex.StackTrace, ModifiedBy = "Calendar Service Error : Update()", DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm") }; new LogsService().Create(error); msg = "Unexpected error encountered. Please contact your system administrator."; } return(msg); }
public static TTarget MapTo <TTarget>(this CrewViewModel source) where TTarget : Crew { return(Mapper.Map <CrewViewModel, TTarget>(source)); }
public CrewView() { this.InitializeComponent(); ViewModel = new CrewViewModel(); this.DataContext = new Crew(); }
public PilotView() { PilotViewModel = new PilotViewModel(); CrewViewModel = new CrewViewModel(); this.InitializeComponent(); }
public ActionResult Edit(CrewViewModel model) { return(CreateEdit(model)); }
/// <summary> /// 陆地端查看船员信息 /// </summary> /// <returns></returns> private IActionResult LandLoad() { //XMQ的组件ID string XMQComId = base.user.ShipId; string tokenstr = HttpContext.Session.GetString("comtoken"); //获取XMQ组件里的WEB组件ID string webIdentity = ManagerHelp.GetLandToId(tokenstr); assembly.SendCrewQuery(XMQComId + ":" + webIdentity); List <ProtoBuffer.Models.CrewInfo> crewInfos = new List <ProtoBuffer.Models.CrewInfo>(); try { bool flag = true; new TaskFactory().StartNew(() => { while (flag) { if (ManagerHelp.CrewReponse != "") { crewInfos = JsonConvert.DeserializeObject <List <ProtoBuffer.Models.CrewInfo> >(ManagerHelp.CrewReponse); flag = false; } Thread.Sleep(500); } }).Wait(timeout); flag = false; } catch (Exception) { } ManagerHelp.CrewReponse = ""; crewVMList = new List <CrewViewModel>(); foreach (var item in crewInfos) { CrewViewModel model = new CrewViewModel() { Id = Convert.ToInt32(item.uid), Job = item.job, Name = item.name, crewPictureViewModels = new List <CrewPictureViewModel>() }; if (item.pictures != null) { foreach (var pic in item.pictures) { CrewPictureViewModel vm = new CrewPictureViewModel() { Id = Guid.NewGuid().ToString(), Picture = pic }; model.crewPictureViewModels.Add(vm); } } crewVMList.Add(model); } var result = new { code = 0, data = crewVMList, count = crewInfos.Count(), isSet = !string.IsNullOrEmpty(XMQComId) ? base.user.EnableConfigure : false }; return(new JsonResult(result)); }