public IHttpActionResult Putproduct(int id, LocationVM location) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != location.Id) { return(BadRequest()); } try { var task = repository.Update(location); task.Wait(); } catch (DbUpdateConcurrencyException) { if (repository.GetLocation(id) == null) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static List <LocationVM> GetLocation(string term) { SqlCommand cmd = new SqlCommand(); cmd.Connection = new SqlConnection(CommanFunctions.GetConnectionString); cmd.CommandText = "SP_QryGetLocation"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@term", term); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); List <LocationVM> objList = new List <LocationVM>(); if (ds != null && ds.Tables.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { LocationVM obj = new LocationVM(); obj.LocationID = CommanFunctions.ParseInt(ds.Tables[0].Rows[i]["LocationID"].ToString()); obj.CityID = CommanFunctions.ParseInt(ds.Tables[0].Rows[i]["CityID"].ToString()); obj.CountryID = CommanFunctions.ParseInt(ds.Tables[0].Rows[i]["CountryID"].ToString()); obj.Location = ds.Tables[0].Rows[i]["Location"].ToString(); obj.CityName = ds.Tables[0].Rows[i]["City"].ToString(); obj.CountryName = ds.Tables[0].Rows[i]["CountryName"].ToString(); objList.Add(obj); } } return(objList); }
public ActionResult DeleteLocation(long LocationID) { ActionResult oResponse = null; LocationVM removeLocation = new LocationVM(); if (Session["UserName"] != null && (int)Session["UserLevel"] == 1) { try { _LocationAccess.DeleteLocation(LocationID); } catch (Exception) { removeLocation.ErrorMessage = "There was a problem deleting the record from the database, please try again later"; } finally { //error is kicked to user, return must be outside this scope. } oResponse = RedirectToAction("ViewLocations", "Location"); } else { oResponse = RedirectToAction("Login", "User"); } return(oResponse); }
public void EditTest() { Location v = new Location(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.Name = "bhVtNC"; context.Set <Location>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(LocationVM)); LocationVM vm = rv.Model as LocationVM; v = new Location(); v.ID = vm.Entity.ID; v.Name = "GV9Ll"; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.Name", ""); _controller.Edit(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <Location>().FirstOrDefault(); Assert.AreEqual(data.Name, "GV9Ll"); } }
public IHttpActionResult PostLocation(LocationVM location) { AuthenticationHeaderValue authenticationHeaderValue = Request.Headers.Authorization; var userNamePasswordString = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationHeaderValue.Parameter)); string usrename = userNamePasswordString.Split(':')[0]; string password = userNamePasswordString.Split(':')[1]; int userId = GetUserId(usrename); var loc = db.Location.Where(x => x.Name == location.Name && x.UserId == userId).FirstOrDefault(); if (loc != null) { return(Ok()); } loc = new Location(); loc.Name = location.Name; loc.Long = location.Long; loc.Lat = location.Lat; loc.CreatedDate = DateTime.Now; loc.UserId = userId; db.Location.Add(loc); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { controller = "locations", id = loc.Id }, loc)); }
public ActionResult Edit(int id) { LocationVM v = new LocationVM(); ViewBag.country = db.CountryMasters.ToList(); var data = (from c in db.LocationMasters where c.LocationID == id select c).FirstOrDefault(); int countryid = (from c in db.CityMasters where c.CityID == data.CityID select c.CountryID).FirstOrDefault().Value; ViewBag.city = (from c in db.CityMasters where c.CountryID == countryid select c).ToList(); if (data == null) { return(HttpNotFound()); } else { v.LocationID = data.LocationID; v.Location = data.Location; v.CityID = data.CityID.Value; v.CountryID = countryid; } return(View(v)); }
public void DeleteTest() { Location v = new Location(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.Name = "bhVtNC"; context.Set <Location>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(LocationVM)); LocationVM vm = rv.Model as LocationVM; v = new Location(); v.ID = vm.Entity.ID; vm.Entity = v; _controller.Delete(v.ID.ToString(), null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { Assert.AreEqual(context.Set <Location>().Count(), 0); } }
public void Update(int id, LocationVM locationVM) { this.Id = locationVM.Id; this.Name_Location = locationVM.Name_Location; this.Floor = locationVM.Floor; this.UpdateDate = DateTimeOffset.Now.ToLocalTime(); }
public ActionResult Create(LocationVM v) { if (ModelState.IsValid) { LocationMaster ob = new LocationMaster(); int max = (from c in db.LocationMasters orderby c.LocationID descending select c.LocationID).FirstOrDefault(); if (max == null) { ob.LocationID = 1; ob.Location = v.Location; ob.CityID = v.CityID; } else { ob.LocationID = max + 1; ob.Location = v.Location; ob.CityID = v.CityID; } db.LocationMasters.Add(ob); db.SaveChanges(); TempData["SuccessMsg"] = "You have successfully added Location."; return(RedirectToAction("Index")); } return(View(v)); }
private location ParseModel(LocationVM vm) { var locModel = new location(); locModel.id = vm.Id; locModel.location_name = vm.LocationName; return(locModel); }
public ActionResult UpdateLocation(long LocationID) { LocationVM updateVM = new LocationVM(); ILocationInfoDO location = _LocationAccess.ViewLocationByID(LocationID); updateVM.Location = LocationMap.MapDOtoPO(location); return(View(updateVM)); }
public void MixedCaseFilter() { var vm = new LocationVM(); vm.Filter("LoNDon"); Assert.IsTrue(vm.Locations != null); Assert.IsTrue(vm.Locations.ContainsKey("London")); }
public void AllLowerFilter() { var vm = new LocationVM(); vm.Filter("london"); Assert.IsTrue(vm.Locations != null); Assert.IsTrue(vm.Locations.ContainsKey("London")); }
public void EmptryFilter() { var vm = new LocationVM(); vm.Filter(""); Assert.IsTrue(vm.Locations != null); Assert.IsTrue(vm.Locations.Count > 0); }
public ActionResult Index() { var model = new LocationVM(); model.Locations = _locationService.GetLocations(); model.Content = _contentService.GetByAlias("rental-companies"); model.Destinations = _locationService.GetAllDestination(); return(View(model)); }
// PUT: api/Locations/5 public HttpResponseMessage UpdateLocation(int id, LocationVM locationVM) { var message = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad Request"); var result = iLocationService.Update(id, locationVM); if (result) { message = Request.CreateResponse(HttpStatusCode.OK); } return(message); }
// POST: api/Locations public HttpResponseMessage InsertLocation(LocationVM locationVM) { var message = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad Request"); var result = iLocationService.Insert(locationVM); if (result) { message = Request.CreateResponse(HttpStatusCode.Created); } return(message); }
public bool Update(int id, LocationVM locationVM) { if (string.IsNullOrWhiteSpace(locationVM.Id.ToString())) { return(status); } else { return(iLocationRepository.Update(id, locationVM)); } }
public IHttpActionResult PostProduct(LocationVM location) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var task = repository.Add(location); task.Wait(); return(CreatedAtRoute("DefaultApi", new { id = location.Id }, location)); }
public async Task <ActionResult> Create(LocationVM location) { if (ModelState.IsValid) { var loc = location.ToLocation(); db.Locations.Add(loc); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(location)); }
public IActionResult SelectLoc() { LocationVM objItemView = new LocationVM(); objItemView.LocationList = (from objCat in _context.Locations select new SelectListItem() { Text = objCat.locationName, Value = objCat.id.ToString(), Selected = true }); return(View(objItemView)); }
public bool Insert(LocationVM locationVM) { if (string.IsNullOrWhiteSpace(Convert.ToString(locationVM.Name_Location))) { return(status); } else if (string.IsNullOrWhiteSpace(Convert.ToString(locationVM.Floor))) { return(status); } else { return(iLocationRepository.Insert(locationVM)); } }
public ActionResult Index() { List <LocationVM> lst = new List <LocationVM>(); var data = db.LocationMasters.ToList(); foreach (var item in data) { LocationVM obj = new LocationVM(); obj.LocationID = item.LocationID; obj.Location = item.Location; obj.CityID = item.CityID.Value; lst.Add(obj); } return(View(data)); }
public ActionResult AddLocation(LocationVM viewModel) { ActionResult oResponse = null; if (Session["UserName"] != null && (int)Session["UserLevel"] == 1) { if (ModelState.IsValid) { try { ILocationInfoDO locationform = LocationMap.MapPOtoDO(viewModel.Location); _LocationAccess.InsertLocation(locationform); } catch (Exception e) { if (e.Message.Contains("duplicate")) { viewModel.ErrorMessage = String.Format("There is already a {0} in the database.", viewModel.Location.LocationName); } else { viewModel.ErrorMessage = "We apologize but we were unable to handle your request at this time."; } } finally { //nothing to do here } if (viewModel.ErrorMessage == null) { oResponse = RedirectToAction("ViewLocations", "Location"); } else { oResponse = View(viewModel); } } else { oResponse = View(viewModel); } } else { oResponse = RedirectToAction("Login", "User"); } return(oResponse); }
public bool Update(int id, LocationVM LocationVM) { var get = Get(id); if (get != null) { get.Update(id, LocationVM); myContext.Entry(get).State = EntityState.Modified; myContext.SaveChanges(); return(true); } else { return(false); } }
public ActionResult AddLocation() { ActionResult oResponse = null; if (Session["Username"] == null || (int)Session["UserLevel"] != 1) { oResponse = RedirectToAction("Login", "User"); return(oResponse); } else { LocationVM newVM = new LocationVM(); oResponse = View(newVM); return(oResponse); } }
public List <LocationVM> GetAllATMS() { List <LocationVM> locations = new List <LocationVM>(); var atms = context.ATMs; foreach (var a in atms) { LocationVM atm = new LocationVM { Lat = a.Lat, Long = a.Long }; locations.Add(atm); } return(locations); }
public ActionResult EditLocation(int id) { ILocationRepo locorepo = LocationRepoFactory.Create(); var location = locorepo.GetLocationById(id); var model = new LocationVM { LocationID = location.LocationID, LocationName = location.LocationName, LocationAddress = location.LocationAddress, LocationDescription = location.LocationDescription, LatitudeCoordinate = location.LatitudeCoordinate, LongitudeCoordinate = location.LongitudeCoordinate, }; locorepo.EditLocation(location); return(View(model)); }
public bool Insert(LocationVM LocationVM) { var push = new Location(LocationVM); myContext.Locations.Add(push); var result = myContext.SaveChanges(); if (result > 0) { status = true; } else { return(status); } return(status); }
public List <LocationVM> GetLocations() { var locationList = (from l in db.Location select l).ToList(); List <LocationVM> locList = new List <LocationVM>(); foreach (var loc in locationList) { LocationVM location = new LocationVM(); location.LocationId = loc.LocationId; location.LocatioName = loc.LocationName; location.Type = loc.Type; locList.Add(location); } return(locList); }
public bool ImportLocation(LocationVM location) { throw new NotImplementedException(); }
public bool SaveLocation(LocationVM newTag) { throw new NotImplementedException(); }