Beispiel #1
0
        // POST: api/Employees

        public IHttpActionResult PostRequest(RequestWithoutDate request)
        {
            Tuple <bool, string, IQueryable <Vehicle> > tuple;
            string msg = "";

            try
            {
                Vehicle result = dbVeh.Vehicles.SingleOrDefault(b => b.VehicleID == request.VehicleID);
                if (result != null && result.EnabledFlag == 0)
                {
                    result.EnabledFlag = 1;
                    dbVeh.SaveChanges();
                    msg = "Araba bırakılmıştır.";
                }
                else if (result != null && result.EnabledFlag == 1)
                {
                    result.EnabledFlag = 0;
                    dbVeh.SaveChanges();
                    msg = "Araba alınmıştır.";
                }
                Request req = new Request
                {
                    RequestID     = request.RequestID,
                    PersonID      = request.PersonID,
                    VehicleID     = request.VehicleID,
                    CreationDate  = DateTime.Now,
                    DurationCheck = request.DurationCheck,
                    RequestType   = msg
                };
                dbReq.Requests.Add(req);
                dbReq.SaveChanges();

                VehicleController a = new VehicleController();
                tuple = new Tuple <bool, string, IQueryable <Vehicle> >(true, msg, a.GetVehicles());
            }
            catch
            {
                VehicleController a = new VehicleController();
                tuple = new Tuple <bool, string, IQueryable <Vehicle> >(false, "Bir hata meydaba gelmiştir, lütfen Uygulama Geliştirm Birimi ile iletişime geçiniz.", a.GetVehicles());
            }

            return(Json(tuple));
        }
Beispiel #2
0
        // PUT: api/Vehicles/5

        public HttpResponseMessage PutVehicle(Vehicle Vehicle)
        {
            if (ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }


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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }