Beispiel #1
0
 public EditBoatModel(IHttpClientFactory clientFactory, ISessionHelper sessionHelper, IBoatFactory boatFactory)
 {
     FormData           = new EditBoatViewModel();
     this.clientFactory = clientFactory;
     this.sessionHelper = sessionHelper;
     this.boatFactory   = boatFactory;
 }
Beispiel #2
0
        public ActionResult Edit(int id)
        {
            try
            {
                // get boat info
                var editedBoat = db.Boats.Where(b => b.BoatId == id).FirstOrDefault();
                if (editedBoat != null)
                {
                    // create edited boat model
                    EditBoatViewModel model = new EditBoatViewModel();
                    model.BoatId     = editedBoat.BoatId;
                    model.BoatCode   = editedBoat.BoatCode;
                    model.BoatOwner  = editedBoat.BoatOwner;
                    model.BoatVolume = editedBoat.BoatVolume;

                    return(View(model));
                }

                // boat not found
                return(RedirectToAction("Message", "Error", new RouteValueDictionary(new { message = "Ghe số hiệu #" + id + " không tồn tại trong hệ thống!" })));
            }
            catch (Exception ex)
            {
                // error
                return(RedirectToAction("Message", "Error", new RouteValueDictionary(new { message = ex.Message })));
            }
        }
Beispiel #3
0
 public Boat BuildForEdit(EditBoatViewModel model, int customerId)
 {
     return(new Boat()
     {
         Id = model.BoatId,
         RegistrationNumber = model.RegistrationNumber,
         Manufacturer = model.Manufacturer,
         ModelYear = model.ModelYear,
         Length = model.Length,
         CustomerId = customerId
     });
 }
Beispiel #4
0
        public ActionResult Edit(EditBoatViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // get current boat info
                    var editedBoat = db.Boats.Where(b => b.BoatId == model.BoatId).FirstOrDefault();
                    if (editedBoat != null)
                    {
                        // update boat info
                        editedBoat.BoatCode   = model.BoatCode;
                        editedBoat.BoatOwner  = model.BoatOwner;
                        editedBoat.BoatVolume = model.BoatVolume;

                        db.SaveChanges();

                        // Write action log
                        string actionLogData = "boatId:" + editedBoat.BoatId + ", boatCode:" + editedBoat.BoatCode;
                        ActionLog.WriteLog(ActionLog.EDIT_BOAT_INFO, actionLogData, User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]);

                        return(RedirectToAction("Index"));
                    }

                    return(RedirectToAction("Message", "Error", new RouteValueDictionary(new { message = "Ghe số hiệu #" + model.BoatCode + " không tồn tại trong hệ thống!" })));
                }

                // invalid boat info
                ModelState.AddModelError("", "Thông tin cập nhật sản phẩm không hợp lệ!!!");
            }
            catch (Exception ex)
            {
                // error
                ModelState.AddModelError("", ex.Message);
            }

            return(View(model));
        }