示例#1
0
        public HttpResponseMessage PostMusterija([FromBody] Musterija mus)
        {
            HttpResponseMessage msg;
            MusterijaRepository musRepo   = new MusterijaRepository();
            AdminRepository     adminRepo = new AdminRepository();
            VozacRepository     vozacRepo = new VozacRepository();

            Musterija m = musRepo.GetOneMusterija(mus.Username);
            Admin     a = adminRepo.GetOneAdmin(mus.Username);
            Vozac     v = vozacRepo.GetOneVozac(mus.Username);

            if (musRepo.MusterijaLogged(m, mus.Password))
            {
                msg = Request.CreateResponse(HttpStatusCode.Created, m);
                msg.Headers.Location = new Uri(Request.RequestUri + m.Username);
            }
            else if (adminRepo.AdminLogged(a, mus.Password))
            {
                msg = Request.CreateResponse(HttpStatusCode.Created, a);
                msg.Headers.Location = new Uri(Request.RequestUri + a.Username);
            }
            else if (vozacRepo.VozacLogged(v, mus.Password))
            {
                msg = Request.CreateResponse(HttpStatusCode.Created, v);
                msg.Headers.Location = new Uri(Request.RequestUri + v.Username);
            }
            else
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User isn't registered.");
            }

            return(msg);
        }
        public HttpResponseMessage GetMusterija()
        {
            HttpResponseMessage msg;
            MusterijaRepository repo = new MusterijaRepository();

            try
            {
                List <Musterija> list = repo.GetMusterije();

                if (list == null)
                {
                    msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User doesn't exist");
                }
                else
                {
                    msg = Request.CreateResponse(HttpStatusCode.OK, list);
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User doesn't exist");
            }

            return(msg);
        }
示例#3
0
        public HttpResponseMessage PutChangedRole(Musterija m)  //kada admin menja ulogu korisnika (musterija - vozac)
        {
            HttpResponseMessage msg;
            MusterijaRepository repo  = new MusterijaRepository();
            VozacRepository     repoV = new VozacRepository();

            Musterija mus = repo.GetOneMusterija(m.Username);
            Vozac     voz = repoV.GetOneVozac(m.Username);

            try
            {
                if (mus != null)
                {
                    if (m.Role == Enums.Roles.Driver)
                    {
                        DeleteEntityMusterija(mus, m);

                        msg = Request.CreateResponse(HttpStatusCode.OK, mus);
                        msg.Headers.Location = new Uri(Request.RequestUri + mus.Username);
                    }
                    else
                    {
                        msg = Request.CreateResponse(HttpStatusCode.OK, mus);
                        msg.Headers.Location = new Uri(Request.RequestUri + mus.Username);
                    }
                }
                else if (voz != null)
                {
                    if (m.Role == Enums.Roles.Customer)
                    {
                        DeleteEntityVozac(voz, m);

                        msg = Request.CreateResponse(HttpStatusCode.OK, voz);
                        msg.Headers.Location = new Uri(Request.RequestUri + voz.Username);
                    }
                    else
                    {
                        msg = Request.CreateResponse(HttpStatusCode.OK, voz);
                        msg.Headers.Location = new Uri(Request.RequestUri + voz.Username);
                    }
                }
                else
                {
                    msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occured while updating");
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occured while updating");
            }

            return(msg);
        }
示例#4
0
        public HttpResponseMessage PostMusterija([FromBody] Musterija k)
        {
            HttpResponseMessage msg;
            MusterijaRepository repo = new MusterijaRepository();
            VozacRepository     vrep = new VozacRepository();
            AdminRepository     arep = new AdminRepository();

            bool status = Validation(k);

            if (!status)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "You are not hacker, stop messing with JS"));
            }

            try
            {
                using (var db = new SystemDBContext())
                {
                    Musterija must = repo.GetOneMusterija(k.Username);
                    Vozac     v    = vrep.GetOneVozac(k.Username);
                    Admin     ad   = arep.GetOneAdmin(k.Username);

                    if (must == null && v == null && ad == null)
                    {
                        db.Musterije.Add(k);
                        db.SaveChanges();

                        msg = Request.CreateResponse(HttpStatusCode.Created, k);
                        msg.Headers.Location = new Uri(Request.RequestUri + k.Username);
                    }
                    else
                    {
                        msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User already exist");
                    }

                    return(msg);
                }
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
示例#5
0
        public HttpResponseMessage GetMusterija(string username)
        {
            HttpResponseMessage msg;
            MusterijaRepository repo  = new MusterijaRepository();
            AdminRepository     arepo = new AdminRepository();
            VozacRepository     vrepo = new VozacRepository();

            try
            {
                Musterija m = repo.GetOneMusterija(username);
                Admin     a = arepo.GetOneAdmin(username);
                Vozac     v = vrepo.GetOneVozac(username);

                if (m != null)
                {
                    msg = Request.CreateResponse(HttpStatusCode.OK, m);
                }
                else if (a != null)
                {
                    msg = Request.CreateResponse(HttpStatusCode.OK, a);
                }
                else if (v != null)
                {
                    msg = Request.CreateResponse(HttpStatusCode.OK, v);
                }
                else
                {
                    msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User is not registered.");
                }
            }
            catch (Exception e)
            {
                msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"Error - {e.Message}");
            }

            return(msg);
        }