Ejemplo n.º 1
0
        public bool Edit(RiderInfo rider)
        {
            try
            {
                var ctx = HttpContext.Current;
                //try
                //{
                //    if (ctx != null)
                //    {
                //        var currentData = ((List<RiderInfo>)ctx.Cache[CacheKey]).ToList();
                //        RiderInfo user_ = currentData.Where(p => p.ride_id = rider.ride_id, p => p.user_id = rider.user_id); // Find(p => p.user_id == user.user_id);
                //        currentData.Remove(user_);
                //        currentData.Add(user);
                //        ctx.Cache[CacheKey] = currentData.ToArray();
                //    }
                //}
                //catch (Exception ex)
                //{
                //    Console.WriteLine(ex.ToString());
                //    return false;
                //}

                db.Entry(rider).State = EntityState.Modified;
                db.SaveChanges();
                return true;

            }
            catch (System.Data.DataException ex)
            {
                // Shud do some logging
                Console.WriteLine(ex.ToString());
                //throw new System.Data.DataException();
                return false;
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post(RiderInfo rider)
        {
            // if state is not valid  method aborts the request and returns a Bad Request (400) status code
            if (!this.ModelState.IsValid)
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest));

            this.rider.SaveRider(rider);

            HttpContext context = HttpContext.Current;

            var response = Request.CreateResponse(HttpStatusCode.Created, rider);
            response.Headers.Add("Access-Control-Allow-Origin", "*");

            return response;
        }
Ejemplo n.º 3
0
        public bool SaveRider(RiderInfo rider)
        {
            var ctx = HttpContext.Current;
            try
            {
                // add information to the cache
                //var currentData = ((List<RiderInfo>)ctx.Cache[CacheKey]).ToList();
                //currentData.Add(rider);
                //ctx.Cache[CacheKey] = currentData.ToArray();

                // add data to the database
                db.RiderInfoes.Add(rider);
                db.SaveChanges();

                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return false;
            }
        }
Ejemplo n.º 4
0
 public bool SaveRider(RiderInfo rider)
 {
     return rider_repository.SaveRider(rider);
 }
Ejemplo n.º 5
0
 public bool Edit(RiderInfo rider)
 {
     return rider_repository.Edit(rider);
 }
Ejemplo n.º 6
0
        public HttpResponseMessage SaveRider(RiderInfo rider_)
        {
            if (!this.ModelState.IsValid)
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest));

            if (rider_ == null)
                throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound));

            bool result = rider.Edit(rider_);

            var response = Request.CreateResponse(HttpStatusCode.OK, result);
            response.Headers.Add("Access-Control-Allow-Origin", "*");
            return response;
        }