public async Task <IActionResult> Edit(int id, [Bind("Id,DateTimePosted,DateTimeChanged,ApplicationUserId,PlanedDateTime,StartDateTime,EndDateTime,AktivitetId,Description")] PlanPost planPost) { if (id != planPost.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(planPost); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlanPostExists(planPost.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(IndexPlanPosts))); } ViewData["AktivitetId"] = new SelectList(_context.Set <Aktivitet>(), "Id", "AktivitetsBeskrivning", planPost.AktivitetId); ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "FullName", planPost.ApplicationUserId); return(View(planPost)); }
public async Task <IActionResult> PostPlan([FromRoute] int userId, [FromBody] PlanPost planPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var plan = new Plan() { Amount = planPost.Amount, EndDate = DateTime.Parse(planPost.EndDate), StartDate = DateTime.Parse(planPost.StartDate), UserID = userId }; _context.Plans.Add(plan); await _context.SaveChangesAsync(); } catch (Exception e) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> CreatePlanPost([Bind("Id,DateTimePosted,DateTimeChanged,ApplicationUserId,PlanedDateTime,StartDateTime,EndDateTime,AktivitetId,Description")] PlanPost planPost) { if (ModelState.IsValid) { _context.Add(planPost); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(IndexPlanPosts))); } ViewData["AktivitetId"] = new SelectList(_context.Set <Aktivitet>(), "Id", "AktivitetsBeskrivning", planPost.AktivitetId); ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "FullName", planPost.ApplicationUserId); return(View(planPost)); }
/// <summary> /// posts a plan to the central server /// </summary> /// <param name="plan"></param> public void PostPlan(Plan plan) { StartCoroutine(SessionLib.FullWebRequest(GetCentralDatastoreEndpoint() + "plan/", "Post", request => { // create a post plan object PlanPost planPost = new PlanPost(); planPost.tag = plan.tag; planPost.scenario = plan.scenario.id; planPost.paths = new List <PlanVehicleDeliveryPost>(); foreach (VehicleDelivery p in plan.paths) { if (p.customers.Count > 0) { PlanVehicleDeliveryPost planpath = new PlanVehicleDeliveryPost(); planpath.vehicle = p.vehicle.id; planpath.warehouse = p.warehouse.id; planpath.customers = new List <int>(); planpath.leavetime = 0; planpath.returntime = p.customers[p.customers.Count - 1].deliverytime; foreach (CustomerDelivery customerpath in p.customers) { planpath.customers.Add(customerpath.id); } planPost.paths.Add(planpath); } } string postData = JsonConvert.SerializeObject(planPost); Debug.Log(postData); request.redirectLimit = 0; byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(postData); request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); resultstr = " Submit Plan : " + getServerResponse(request.responseCode); })); }