コード例 #1
0
        public IHttpActionResult PuttblUser(string id, tblUser tblUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblUser.UserID)
            {
                return(BadRequest());
            }

            db.Entry(tblUser).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tblUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public ActionResult Edit(FlightViewModel flightinfo)
        {
            if (ModelState.IsValid)
            {
                //insert gar
                //converting view model to entity model
                tblFlight dbFlight = new tblFlight();
                dbFlight.ID         = flightinfo.ID;
                dbFlight.FlightNo   = flightinfo.FlightNo;
                dbFlight.Detail     = flightinfo.Detail;
                dbFlight.FlightName = flightinfo.FlightName;

                if (flightinfo.FileFlightLogo != null)
                {
                    var fileName = dbFlight.FlightNo + ".jpg";
                    var path     = Server.MapPath("~/FlightImages");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    flightinfo.FileFlightLogo.SaveAs(path + "/" + fileName);
                    dbFlight.FlightLogo = fileName;
                }

                db.Entry(dbFlight).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(flightinfo));
        }
コード例 #3
0
        public ActionResult Edit(FlightFareViewModel fare)
        {
            fare.ListFlight = (from c in db.tblFlights.ToList()
                               select new SelectListItem
            {
                Text = c.FlightNo,
                Value = c.ID.ToString()
            }).ToList();
            fare.ListClass = (from c in db.tblClasses.ToList()
                              select new SelectListItem
            {
                Text = c.Class,
                Value = c.ID.ToString()
            }).ToList();
            fare.ListRoute = (from c in db.tblRoutes.ToList()
                              select new SelectListItem
            {
                Text = c.Departure + '-' + c.Arrival,
                Value = c.ID.ToString()
            }).ToList();
            fare.ListPassengerType = (from c in db.tblPassengerTypes.ToList()
                                      select new SelectListItem
            {
                Text = c.PassengerType,
                Value = c.ID.ToString()
            }).ToList();
            if (ModelState.IsValid)
            {
                try
                {
                    //insert gar
                    //converting view model to entity model
                    var     config      = new MapperConfiguration(x => { x.CreateMap <FlightFareViewModel, tblFare>(); });
                    var     _mapper     = config.CreateMapper();
                    tblFare entitymodel = _mapper.Map <tblFare>(fare);

                    //update database
                    db.Entry(entitymodel).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            return(View(fare));
        }
コード例 #4
0
 public ActionResult ChangePassword(ChangePasswordViewModel cpViewModel)
 {
     if (ModelState.IsValid)
     {
         tblUserInformation dbUser = db.tblUserInformations.Where(c => c.ID == cpViewModel.UserId).FirstOrDefault();
         if (dbUser != null)
         {
             dbUser.Password        = cpViewModel.Password;
             db.Entry(dbUser).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index", "Login"));
         }
     }
     return(View(cpViewModel));
 }
コード例 #5
0
        public ActionResult Edit(UserInformationViewModel userinfo)
        {
            if (ModelState.IsValid)
            {
                //insert gar
                //converting view model to entity model
                var config  = new MapperConfiguration(x => { x.CreateMap <UserInformationViewModel, tblUserInformation>(); });
                var _mapper = config.CreateMapper();
                tblUserInformation entitymodel = _mapper.Map <tblUserInformation>(userinfo);

                //update database
                db.Entry(entitymodel).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(userinfo));
        }
コード例 #6
0
        public ActionResult Edit(FlightSeatViewModel seat)
        {
            seat.ListFlight = (from c in db.tblFlights.ToList()
                               select new SelectListItem
            {
                Text = c.FlightNo,
                Value = c.ID.ToString()
            }).ToList();
            seat.ListClass = (from c in db.tblClasses.ToList()
                              select new SelectListItem
            {
                Text = c.Class,
                Value = c.ID.ToString()
            }).ToList();
            if (ModelState.IsValid)
            {
                try
                {
                    //insert gar
                    //converting view model to entity model
                    var config = new MapperConfiguration
                                     (x => { x.CreateMap <FlightSeatViewModel, tblFlightSeat>(); });
                    var           _mapper     = config.CreateMapper();
                    tblFlightSeat entitymodel = _mapper.Map <tblFlightSeat>(seat);

                    //update database
                    db.Entry(entitymodel).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            return(View(seat));
        }