コード例 #1
0
        public IHttpActionResult PutCountry(int id, Country country)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public async Task <IActionResult> PutLocation(int id, Location location)
        {
            if (id != location.Id)
            {
                return(BadRequest());
            }

            _context.Entry(location).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LocationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #3
0
ファイル: PostCheck.cs プロジェクト: SeanGallen/geoLocation
        public async Task <string> AddIt(LocationContext context, VehicleLocation vehicleLocation)
        {
            _context = context;
            _context.VehicleLocations.Add(vehicleLocation);
            await _context.SaveChangesAsync();

            string vehicleLatLong = "";

            vehicleLatLong += vehicleLocation.VehicleId;
            vehicleLatLong += "#";
            vehicleLatLong += vehicleLocation.Latitude;
            vehicleLatLong += ",";
            vehicleLatLong += vehicleLocation.Longitude;

            vehicleLocation.VehicleLatLong        = vehicleLatLong;
            _context.Entry(vehicleLocation).State = EntityState.Modified;
            _context.VehicleLocations.Update(vehicleLocation);

            try
            {
                await _context.SaveChangesAsync();

                return("Response:{ status: Succes, description: Vehicle data saved}");
            }
            catch (DbUpdateConcurrencyException e)
            {
                return("Look here " + e.Message);
            }
        }
コード例 #4
0
        public async Task <string> ChangeActive(int id)
        {
            var vehicleLocation = await _context.VehicleLocations.SingleOrDefaultAsync(m => m.Id == id);

            if (vehicleLocation != null)
            {
                vehicleLocation.Active = 0;
            }
            _context.Entry(vehicleLocation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VehicleLocationExists(id))
                {
                    return("not Found");
                }
                else
                {
                    throw;
                }
            }
            return("worked");
        }
コード例 #5
0
        public async Task <IActionResult> PutComment([FromRoute] int id, [FromBody] Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #6
0
 public ActionResult Edit([Bind(Include = "RegionId,RegionName")] Region region)
 {
     if (ModelState.IsValid)
     {
         db.Entry(region).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(region));
 }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "CityId,CityName,RegionId")] City city)
 {
     if (ModelState.IsValid)
     {
         db.Entry(city).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RegionId = new SelectList(db.Regions, "RegionId", "RegionName", city.RegionId);
     return(View(city));
 }
コード例 #8
0
ファイル: GetRequests.cs プロジェクト: SeanGallen/geoLocation
        public async Task <string> SaveAddress(string newAddress, VehicleLocation vehicleLocation)
        {
            vehicleLocation.Address = newAddress;
            _context.Entry(vehicleLocation).State = EntityState.Modified;
            _context.VehicleLocations.Update(vehicleLocation);

            try
            {
                await _context.SaveChangesAsync();

                return("Response:{ status: Succes, description: Vehicle data saved}");
            }
            catch (DbUpdateConcurrencyException e)
            {
                return("Look here " + e.Message);
            }
        }
コード例 #9
0
        public async Task <bool> PutLocation(int id, Location location)
        {
            context.Entry(location).State = EntityState.Modified;

            try
            {
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!locationExists(id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }

            return(true);
        }
コード例 #10
0
 public void Update(T obj)
 {
     dbSet.Attach(obj);
     db.Entry(obj).State = EntityState.Modified;
 }
コード例 #11
0
 public virtual void Update(T entity)
 {
     dbset.Attach(entity);
     ctx.Entry(entity).State = EntityState.Modified;
 }