예제 #1
0
        public HttpResponseMessage PostLocation([FromBody] Adresa address)
        {
            HttpResponseMessage msg  = new HttpResponseMessage();
            LokacijaRepository  repo = new LokacijaRepository();

            try
            {
                using (SystemDBContext db = new SystemDBContext())
                {
                    Lokacija lk = new Lokacija()
                    {
                        Address = new Adresa()
                        {
                            FullAddress = address.FullAddress
                        },
                        CoordinateX = 0,
                        CoordinateY = 0,
                        LocationId  = repo.GetLokacije().Count + 1
                    };

                    db.Lokacije.Add(lk);
                    db.SaveChanges();

                    msg = Request.CreateResponse(HttpStatusCode.Created, lk.LocationId); //vracam ID sacuvane lokacije
                    msg.Headers.Location = new Uri(Request.RequestUri + lk.LocationId.ToString());
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occured while updating");
            }

            return(msg);
        }
예제 #2
0
        public HttpResponseMessage GetAddress(int id)
        {
            HttpResponseMessage msg;
            LokacijaRepository  repo = new LokacijaRepository();

            try
            {
                Lokacija loc = repo.GetOneLocation(id);

                if (loc == null)
                {
                    msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Location doesn't exist");
                }
                else
                {
                    msg = Request.CreateResponse(HttpStatusCode.OK, loc.Address.FullAddress); //vracam full adresu da bih je prikazao
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Location doesn't exist");
            }

            return(msg);
        }
예제 #3
0
 public AdminLokacijaForm(Klientas klientas)
 {
     InitializeComponent();
     this.klientas = klientas;
     transLokRep   = new LokacijaRepository();
     klientoLokRep = new KlientoLokacijaRepository();
     transRep      = new TransportRepository();
     klientoRep    = new UsersRepository();
 }
예제 #4
0
 public AdminNuomaForm(Klientas klientas)
 {
     InitializeComponent();
     this.klientas = klientas;
     nuomaRep      = new NuomaRepository();
     transRep      = new TransportRepository();
     usersRep      = new UsersRepository();
     rezRep        = new RezervacijaRepository();
     transLokRep   = new LokacijaRepository();
 }
예제 #5
0
        public HttpResponseMessage PutDriveRequest([FromBody] JToken token)
        {
            HttpResponseMessage msg;
            LokacijaRepository  repo  = new LokacijaRepository();
            VozacRepository     vrepo = new VozacRepository();

            var id       = token.Value <int>("id");
            var location = token.Value <string>("location");
            var type     = token.Value <string>("type");

            try
            {
                Vozac vozac = vrepo.GetVozace().Find(x => x.Car.TypeString == type);

                if (vozac == null)
                {
                    msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"That type of car isn't available.");
                }
                else
                {
                    using (SystemDBContext db = new SystemDBContext())
                    {
                        Voznja   v = db.Voznje.FirstOrDefault(x => x.Id == id);
                        Lokacija l = db.Lokacije.FirstOrDefault(x => x.LocationId == v.StartPointID);

                        v.TypeOfCar           = GetTypeInEnum(type);
                        l.Address.FullAddress = location;

                        db.SaveChanges();

                        msg = Request.CreateResponse(HttpStatusCode.OK, v);
                    }
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"Error occured while updating drive - {e.Message}");
            }

            return(msg);
        }