Пример #1
0
 public IActionResult UpdateFlight(int id, [FromBody] Flights newflight)
 {
     _log4net.Info(" Http UpdateFlight request Initiated");
     if (id == 0 || newflight == null)
     {
         return(BadRequest());
     }
     try
     {
         int res = repo.UpdateFlight(id, newflight);
         if (res == 1)
         {
             return(Ok());
         }
         return(BadRequest());
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
        public ActionResult Edit([Bind(Include = "FlightId,Flight_Nr,From,To,ArriveTime,ExpectedTime,StatusId,CompanyId,FlightType,CreatedOnDate,LastModifiedOnDate,CreatedByUserId,LastModifiedByUserId,IsDeleted")] Flights flights)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    flights.LastModifiedByUserId = User.Identity.GetUserId();
                    flights.LastModifiedOnDate   = DateTime.Now;
                    flightRepository.UpdateFlight(flights);
                    flightRepository.Save();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError(string.Empty, "Unable to save changes. Try again.");
            }

            ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", flights.CompanyId);
            ViewBag.StatusId  = new SelectList(db.Statuses, "StatusId", "Name", flights.StatusId);
            return(View(flights));
        }