public ActionResult AddBoat(BoatModel boatModel) { if (!SessionManager.checkCurrentUserType(UserType.MAINTENANCE_PERSON)) { return(new HttpStatusCodeResult(403)); } boatModel.locationList = BL.MainClass.Instance.getLocations(); boatModel.file.SaveAs(Server.MapPath("~/Public/Images/") + boatModel.file.FileName); boatModel.imagePath = boatModel.file.FileName; // string path = Path.Combine(Server.MapPath("~/Public/Images"), Path.GetFileName(boatModel.file.FileName)); //boatModel.ImageFile.SaveAs(path); string fileName = boatModel.file.FileName; //string extension = Path.GetExtension(boatModel.file.FileName); //fileName = fileName + extension; string imagePath = "Public/Images/" + fileName; if (ModelState.IsValid) { BL.Location location = MainClass.Instance.getLocations().Find(v => v.id == boatModel.locationId); if (location != null) { if (location.addBoat(new BL.Boat(boatModel.name, boatModel.capacity, boatModel.pricePerHour, boatModel.seasonId, imagePath))) { ViewBag.Status = true; ViewBag.Message = "Boat added successfully"; return(View(boatModel)); } } } ViewBag.Status = false; ViewBag.Message = "Boat could not be added. Please make sure that you select a location."; return(View(boatModel)); }