// GET: Infringements/Delete/5 public ActionResult Delete(int?id) { using (log4net.NDC.Push("Delete_Infrin GET")) { if (id <= 0) { _logger.Warn("Id cannot be less than 1, bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = db.infringements.FirstOrDefault(x => x.Id == id); ViewBag.Images = db.infringementpictures .Where(x => x.InfringementId == id) .Select(x => x.Location) .ToList(); if (entity == null) { _logger.Warn("infrin. could not be found, not found "); return(HttpNotFound()); } _logger.Info("Infrin. found, mapping to view model to editing purposes"); return(View(MvcModelToDatabaseModelMapper.MapInfringementForDisplayDelete(entity))); } }
public ActionResult Edit([Bind(Include = "Id,Type,Amount,SortOrder")] InfringementTypeModel model) { using (log4net.NDC.Push("Post for editing infrin. type")) { if (ModelState.IsValid) { _logger.Info("Model is valid, search for city in the database" + model.Id); _logger.Info(model); var entity = _entities.infringementtypes.FirstOrDefault(x => x.Id == model.Id); if (entity == null) { _logger.Warn("Infrin. type not found"); return(new HttpNotFoundResult()); } _logger.Info("Infrin. type found, updating the database entity"); MvcModelToDatabaseModelMapper.MapInfringementTypeForEdit(model, entity); try { _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("Infrin. type could not be updated", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } return(View(model)); } }
public ActionResult Create([Bind(Include = "Name,SortOrder")] CityModel model) { using (log4net.NDC.Push("Create city post")) { _logger.Info("Save specific city"); _logger.Info(model); if (ModelState.IsValid) { _logger.Info("Model is valid, map to entity model"); var entityModel = MvcModelToDatabaseModelMapper.MapCityForCreate(model); _entities.cities.Add(entityModel); try { _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("Saving of city entity failed", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } return(View(model)); } }
public ActionResult Edit(int id, CityModel cityModel) { using (log4net.NDC.Push("Post for editing city")) { if (ModelState.IsValid) { _logger.Info("Model is valid, search for city in the database" + id); _logger.Info(cityModel); var cityEntity = _entities.cities.FirstOrDefault(x => x.id == id); if (cityEntity == null) { _logger.Warn("City not found"); return(new HttpNotFoundResult()); } _logger.Info("City found, updating the database entity"); MvcModelToDatabaseModelMapper.MapCityForEdit(cityModel, cityEntity); try { _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("City could not be updated", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } return(View(cityModel)); } }
public ActionResult Edit([Bind(Include = "Id,CityId,Name,Address,ImageLocation,Description,Longitude,Latitude,SortOrder")] CarParkBuildingModel model) { using (log4net.NDC.Push("Edit Building POST")) { _logger.Info("Check if model is valid"); if (ModelState.IsValid) { _logger.Info("Model is valid, save building"); var entityRecord = _entities.parking_location.FirstOrDefault(x => x.Id == model.Id); MvcModelToDatabaseModelMapper.MapBuildingForEdit(model, entityRecord); try { _logger.Info("Save building"); _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("building could not be updated", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } _logger.Warn("Model is not valid, cannot save building"); return(View(model)); } }
public ActionResult Edit([Bind(Include = "Id,MakeId,Name,SortOrder")] ModelForCarMakeModel model) { using (log4net.NDC.Push("Edit Building POST")) { _logger.Info("Check if model is valid"); if (ModelState.IsValid) { _logger.Info("Model is valid, save model"); var entityRecord = _entities.carmodels.FirstOrDefault(x => x.Id == model.Id); MvcModelToDatabaseModelMapper.MapCarModelForEdit(model, entityRecord); try { _logger.Info("Save model"); _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("model could not be updated", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } _logger.Warn("Model is not valid, cannot save car model"); return(View(model)); } }
// GET: Cities/Delete/5 public ActionResult Delete(int id) { using (log4net.NDC.Push("Delete_Car_Model")) { if (id <= 0) { _logger.Warn("Id cannot be less than 1, bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = _entities.carmodels.FirstOrDefault(x => x.Id == id); if (entity == null) { _logger.Warn("Car model could not be found, not found "); return(HttpNotFound()); } _logger.Info("car model found, mapping to view model to editing purposes"); var make = _entities.makes.FirstOrDefault(x => x.id == entity.MakeId); if (make != null) { _logger.Info("City found " + entity.MakeId); ViewBag.CityName = make.Name; return(View(MvcModelToDatabaseModelMapper.MapCarModelForDisplay(entity))); } else { _logger.Warn("Make not found - MakeId=" + entity.MakeId); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } } }
// GET: Building/Details/5 public ActionResult Details(int id) { using (log4net.NDC.Push("Building_Detail_View")) { if (id <= 0) { _logger.Warn("Id cannot be less than 1, sending back bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = _entities.parking_location.FirstOrDefault(x => x.Id == id); if (entity == null) { _logger.Warn("Building could not be found, id = " + id); return(HttpNotFound()); } _logger.Info("Building found create view model and send across to view"); var model = MvcModelToDatabaseModelMapper.MapBuildingForDisplay(entity); var city = _entities.cities.FirstOrDefault(x => x.id == entity.CityId); if (city != null) { _logger.Info("City found " + entity.CityId); ViewBag.CityName = city.name; return(View(model)); } else { _logger.Warn("City not found - CityId=" + entity.CityId); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } } }
public ActionResult Create([Bind(Include = "Id,CityId,Name,Address,ImageLocation,Description,Longitude,Latitude,SortOrder")] CarParkBuildingModel model) { using (log4net.NDC.Push("Create building post")) { _logger.Info("Save specific building"); _logger.Info(model); if (ModelState.IsValid) { _logger.Info("Model is valid, map to entity model"); var entityModel = MvcModelToDatabaseModelMapper.MapBuildingForCreate(model); _entities.parking_location.Add(entityModel); try { _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("Saving of building entity failed", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } return(View(model)); } }
// GET: Cities/Delete/5 public ActionResult Delete(int id) { using (log4net.NDC.Push("Delete_Building")) { if (id <= 0) { _logger.Warn("Id cannot be less than 1, bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = _entities.parking_location.FirstOrDefault(x => x.Id == id); if (entity == null) { _logger.Warn("Building could not be found, not found "); return(HttpNotFound()); } _logger.Info("Building found, mapping to view model to editing purposes"); var city = _entities.cities.FirstOrDefault(x => x.id == entity.CityId); if (city != null) { _logger.Info("City found " + entity.CityId); ViewBag.CityName = city.name; return(View(MvcModelToDatabaseModelMapper.MapBuildingForDisplay(entity))); } else { _logger.Warn("City not found - CityId=" + entity.CityId); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } } }
public ActionResult Edit([Bind(Include = "Id,IncidentTime,Number,Rego,ParkingLocationId,MakeId,ModelId,OtherMake,OtherModel,CarModel,InfringementTypeId,Amount,Comment,Latitude,Longitude,User,StatusId,,DueDate,AfterDueDate,Name,Street1,Street2,Suburb,PostCode,CountryId,CityName")] InfringementModel model) { using (log4net.NDC.Push("Post for editing infrin.")) { if (ModelState.IsValid) { _logger.Info("Model is valid, search for infringment in the database" + model.Number); _logger.Info(model); var entity = db.infringements.FirstOrDefault(x => x.Number == model.Number); if (entity == null) { _logger.Warn("Infrin. not found"); return(new HttpNotFoundResult()); } _logger.Info("Infrin. found, updating the database entity"); MvcModelToDatabaseModelMapper.MapInfringementForEdit(model, entity); try { entity.User = "******"; db.SaveChanges(); } catch (Exception ex) { _logger.Warn("Infrin. could not be updated", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } return(View(model)); } }
// GET: Building/Details/5 public ActionResult Details(int id) { using (log4net.NDC.Push("Model_Detail_View")) { if (id <= 0) { _logger.Warn("Id cannot be less than 1, sending back bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = _entities.carmodels.FirstOrDefault(x => x.Id == id); if (entity == null) { _logger.Warn("Models could not be found, id = " + id); return(HttpNotFound()); } _logger.Info("Model found create view model and send across to view"); var model = MvcModelToDatabaseModelMapper.MapCarModelForDisplay(entity); var make = _entities.makes.FirstOrDefault(x => x.id == entity.MakeId); if (make != null) { _logger.Info("Make found " + entity.MakeId); ViewBag.MakeName = make.Name; return(View(model)); } else { _logger.Warn("Make not found - MakeId=" + entity.MakeId); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } } }
// GET: Building/Create public ActionResult Create() { var model = new ModelForCarMakeModel(); model.SortOrder = (_entities.carmodels.Max(x => x.SortOrder) ?? 0) + 100; MvcModelToDatabaseModelMapper.MapCarModelForCreate(model); PopulateCarModelsInViewBag(0); return(View(model)); }
// GET: Building/Create public ActionResult Create() { var model = new CarParkBuildingModel(); model.SortOrder = (_entities.parking_location.Max(x => x.SortOrder) ?? 0) + 100; MvcModelToDatabaseModelMapper.MapBuildingForCreate(model); PopulateCitiesInViewBag(0); return(View(model)); }
// GET: Cities public ActionResult Index() { using (log4net.NDC.Push("Cities_Index_View")) { _logger.Info("Getting a list of all cities in sort order"); var cities = _entities.cities .OrderBy(x => x.SortOrder) .ToList() .Select(x => MvcModelToDatabaseModelMapper.MapCityForDisplay(x)) .ToList(); return(View(cities)); } }
// GET: Cities public ActionResult Index() { using (log4net.NDC.Push("InfringementType_Index_View")) { _logger.Info("Getting a list of all infringement types in sort order"); var items = _entities.infringementtypes .OrderBy(x => x.SortOrder) .ToList() .Select(x => MvcModelToDatabaseModelMapper.MapInfringementTypeForDisplay(x)) .ToList(); return(View(items)); } }
// GET: Building public ActionResult Index() { using (log4net.NDC.Push("Buildings_Index_View")) { _logger.Info("Getting a list of all buildings in sort order"); var building = _entities.parking_location .OrderBy(x => x.SortOrder) .ToList() .Select(x => MvcModelToDatabaseModelMapper.MapBuildingForDisplay(x)) .ToList(); ViewBag.Cities = _entities.cities.ToDictionary(x => x.id, x => x.name); return(View(building)); } }
// GET: Building public ActionResult Index() { using (log4net.NDC.Push("Models_Index_View")) { _logger.Info("Getting a list of all models in sort order"); var building = _entities.carmodels .OrderBy(x => x.SortOrder) .ToList() .Select(x => MvcModelToDatabaseModelMapper.MapCarModelForDisplay(x)) .ToList(); ViewBag.Makes = _entities.makes.ToDictionary(x => x.id, x => x.Name); return(View(building)); } }
// GET: Cities/Edit/5 public ActionResult Edit(int id) { using (log4net.NDC.Push("Edit_City")) { if (id <= 0) { _logger.Warn("Id cannot be less than 1, bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = _entities.cities.FirstOrDefault(x => x.id == id); if (entity == null) { _logger.Warn("City could not be found, not found "); return(HttpNotFound()); } _logger.Info("City found, mapping to view model to editing purposes"); return(View(MvcModelToDatabaseModelMapper.MapCityForDisplay(entity))); } }
// GET: Cities/Delete/5 public ActionResult Delete(int id) { using (log4net.NDC.Push("Delete_Infrin_type")) { if (id <= 0) { _logger.Warn("Id cannot be less than 1, bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = _entities.infringementtypes.FirstOrDefault(x => x.Id == id); if (entity == null) { _logger.Warn("infrin. type could not be found, not found "); return(HttpNotFound()); } _logger.Info("Infrin. type found, mapping to view model to editing purposes"); return(View(MvcModelToDatabaseModelMapper.MapInfringementTypeForDisplay(entity))); } }
// GET: Cities/Details/5 public ActionResult Details(int id) { using (log4net.NDC.Push("Cityz_Detail_View")) { if (id <= 0) { _logger.Warn("Id caanot be less than 1, sending back bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = _entities.cities.FirstOrDefault(x => x.id == id); if (entity == null) { _logger.Warn("City could not be found, id = " + id); return(HttpNotFound()); } _logger.Info("City found create view model and send across to view"); var model = MvcModelToDatabaseModelMapper.MapCityForDisplay(entity); return(View(model)); } }
// GET: Infringements/Edit/5 public ActionResult Edit(int?id) { using (log4net.NDC.Push("Edit Infringemnet - GET")) { if (id == null) { _logger.Warn("Cannot edit infringement as id was not sent across"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } infringement infringement = db.infringements.Find(id); if (infringement == null) { _logger.Warn("Infringement was not found for id" + id); return(HttpNotFound()); } _logger.Info("infringement found, setting up viewbag and returning view"); ViewBag.Images = db.infringementpictures .Where(x => x.InfringementId == id) .Select(x => x.Location) .ToList(); var infringementCity = db.parking_location .FirstOrDefault(x => x.Id == infringement.ParkingLocationId).CityId; ViewBag.Cities = new SelectList(db.cities, "Id", "Name", infringementCity); ViewBag.Buildings = new SelectList(db.parking_location, "Id", "Name", infringement.ParkingLocationId); ViewBag.Makes = new SelectList(db.makes, "id", "Name", infringement.MakeId); ViewBag.InfringementTypes = new SelectList(db.infringementtypes, "Id", "Type", infringement.InfringementTypeId); ViewBag.Status = new SelectList(db.infringementstatus, "Id", "Name", infringement.StatusId); var model = MvcModelToDatabaseModelMapper.MapInfringementForDisplay(infringement); ViewBag.IncidentTime = model.IncidentTime.ToString("dd/MM/yyyy HH:mm"); ViewBag.Models = new SelectList(db.carmodels.Where(x => x.Id == infringement.MakeId), "Id", "Name"); ViewBag.Countries = new SelectList(db.countries.OrderBy(x => x.CountryName), "Id", "CountryName"); ViewBag.APIServerPath = System.Configuration.ConfigurationManager.AppSettings["APIServerPath"].ToString(); return(View(model)); } }
public ActionResult Create([Bind(Include = "Id,IncidentTime,Number,Rego,CityId,ParkingLocationId,MakeId,ModelId,OtherMake,OtherModel,InfringementTypeId,Amount,Comment,User,UploadTime,Latitude,Longitude,DueDate,AfterDueDate,OwnerName,Street1,Street2,Suburb,PostCode,CountryId,CityName")] InfringementModel infringement, string Submit, string GalleryImageScroll, HttpPostedFileBase upload) { using (log4net.NDC.Push("Create infringement post")) { if (Submit == "Add Photo") { var validImageTypes = new string[] { "image/gif", "image/jpg", "image/jpeg", "image/pjpeg", "image/png" }; if (upload != null && upload.ContentLength > 0) { if (!validImageTypes.Contains(upload.ContentType)) { _logger.Warn("Please choose either a GIF, JPG or PNG image." + upload.ContentType); ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image."); } else { ImageUpload imageUpload = new ImageUpload(); using (var binaryReader = new BinaryReader(upload.InputStream)) { imageUpload.Image = binaryReader.ReadBytes(upload.ContentLength); } imageUpload.FileName = upload.FileName; imageUpload.ContentType = upload.ContentType; List <ImageUpload> imageUploads = (List <ImageUpload>)Session["ImageList"]; imageUploads.Add(imageUpload); Session["ImageList"] = imageUploads; int galleryImageScroll = -1; int.TryParse(GalleryImageScroll, out galleryImageScroll); TempData["GalleryImageScroll"] = galleryImageScroll + 1; } } ViewBag.Cities = new SelectList(db.cities, "id", "name", infringement.CityId); ViewBag.PLocations = new SelectList(db.parking_location.Where(x => x.CityId == infringement.CityId).OrderBy(x => x.SortOrder), "Id", "Name", infringement.ParkingLocationId); ViewBag.Makes = new SelectList(db.makes, "id", "Name"); ViewBag.InfringementTypes = new SelectList(db.infringementtypes, "Id", "Type"); ViewBag.Models = new SelectList(db.carmodels.Where(x => x.Id == 0), "Id", "Name"); ViewBag.Countries = new SelectList(db.countries.OrderBy(x => x.CountryName), "Id", "CountryName"); return(View(infringement)); } else if (Submit == "Save Infringement") { var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); if (ModelState.IsValid) { _logger.Info("model is valid, mapping to entity" + infringement); try { infringement.User = "******"; var infring = db.infringements.FirstOrDefault(x => x.Number == infringement.Number); if (infring != null) { infringement.Number = null; } var entityModel = MvcModelToDatabaseModelMapper.MapInfringementForCreate(infringement); entityModel.CreatedBy = (int)Session["UserId"]; entityModel.CreatedDate = System.DateTime.Now; entityModel.Pay = false; db.infringements.Add(entityModel); db.SaveChanges(); infringement.Number = entityModel.Number; if (Session["ImageList"] != null) { if (db.infringements.FirstOrDefault(x => x.Number == infringement.Number) == null) { _logger.Warn("Infringement number does not exist in the database"); ModelState.AddModelError("infringementNumber", "Infringement Number does not exist"); } else { //IRestRequest request = new RestRequest( // String.Format("infringement/{0}/images", infringement.Number) // , Method.POST); string apiLink = System.Configuration.ConfigurationManager.AppSettings["APIServerPath"]; var client = new RestClient(apiLink + "api"); //"http://localhost:50247/api" List <ImageUpload> imageUploads = (List <ImageUpload>)Session["ImageList"]; try { foreach (ImageUpload imageUpload in imageUploads) { //byte[] fileData = null; //using (var binaryReader = new BinaryReader(upload.InputStream)) //{ // fileData = binaryReader.ReadBytes(upload.ContentLength); //} IRestRequest request = new RestRequest( String.Format("infringement/{0}/images", infringement.Number) , Method.POST); request.AddFileBytes(imageUpload.FileName, imageUpload.Image, imageUpload.FileName, imageUpload.ContentType); request.AddParameter(new Parameter { Name = "Longitude", Type = ParameterType.GetOrPost, Value = infringement.Longitude }); request.AddParameter(new Parameter { Name = "Latitude", Type = ParameterType.GetOrPost, Value = infringement.Latitude }); request.AddParameter(new Parameter { Name = "Description", Type = ParameterType.GetOrPost, Value = imageUpload.FileName }); _logger.Info("Everything is valid, calling the rest client to save image"); IRestResponse response = client.Execute(request); var content = response.Content; // raw content as string // already image information we are stroing through API. //var imageViewModel = new infringementpicture //{ // //Location = String.Format("infringement/{0}/images/{1}", infringement.Number, imageUpload.FileName), // Location = String.Format("{0}/{1}", infringement.Number, imageUpload.FileName), // Latitude = infringement.Latitude, // Longitude = infringement.Longitude, // InfringementId = entityModel.Id // int.Parse(infringement.Number) //}; //db.infringementpictures.Add(imageViewModel); //db.SaveChanges(); } return(RedirectToAction("Index")); } catch (Exception ex) { _logger.Warn("Could not save image", ex); ModelState.AddModelError("ImageUpload", "Could not save image, try again"); return(View(infringement)); } } } } catch (InvalidOfficerCodeException ex) { _logger.Warn("Officer code is invalid"); ModelState.AddModelError("User", "Invalid Officer Code"); _logger.Info("Infringement model is not valid, return back to create view"); ViewBag.Cities = new SelectList(db.cities, "id", "name"); ViewBag.Makes = new SelectList(db.makes, "id", "Name"); ViewBag.InfringementTypes = new SelectList(db.infringementtypes, "Id", "Type"); ViewBag.Countries = new SelectList(db.countries.OrderBy(x => x.CountryName), "Id", "CountryName"); return(View(infringement)); } catch (Exception ex) { _logger.Warn("Saving of infrin. entity failed", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } _logger.Info("Infringement model is not valid, return back to create view"); ViewBag.Cities = new SelectList(db.cities, "id", "name"); ViewBag.Makes = new SelectList(db.makes, "id", "Name"); ViewBag.InfringementTypes = new SelectList(db.infringementtypes, "Id", "Type"); ViewBag.PLocations = new SelectList(db.parking_location.Where(x => x.CityId == infringement.CityId).OrderBy(x => x.SortOrder), "Id", "Name", infringement.ParkingLocationId); ViewBag.Countries = new SelectList(db.countries.OrderBy(x => x.CountryName), "Id", "CountryName"); return(View(infringement)); } return(RedirectToAction("Index")); } }