Esempio n. 1
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            //novi post
            case Resource.Id.novipost:
                var inflater = LayoutInflater.From(this);
                var view     = inflater.Inflate(Resource.Layout.noviPostDialog, null);

                var dialog = new Android.Support.V7.App.AlertDialog.Builder(this);
                dialog.SetView(view);

                dialog.SetPositiveButton("Kreiraj", (sender, args) =>
                {
                    ObjavaCUDto objava = new ObjavaCUDto()
                    {
                        IdLokacije = 1, TekstObjave = view.FindViewById <EditText>(Resource.Id.dialogTextPost).Text
                    };
                    Api.Api.UserNewPost(MSettings.CurrentSession.LoggedUser.UserID, objava);
                });

                dialog.SetNegativeButton("Otkazi", (sender, args) => { dialog.Dispose(); });

                dialog.Show();

                return(true);

            //search
            case Resource.Id.search:
                return(true);

            //odjava
            case Resource.Id.odjavaMenu:
                Api.Api.LogoutUser(MSettings.CurrentSession.SessionID);
                var intent = new Intent(this, typeof(MainActivity));
                intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
                StartActivity(intent);
                this.Finish();
                return(true);

            case Resource.Id.prijatelji:
                var intent2 = new Intent(this, typeof(MojiPrijateljiActivity));
                StartActivity(intent2);
                return(true);

            case Resource.Id.urediProfil:
                var intentUredi = new Intent(this, typeof(UrediProfilActivity));
                StartActivity(intentUredi);
                return(true);

            default:
                return(base.OnOptionsItemSelected(item));
            }
        }
Esempio n. 2
0
        public ObjavaCUDto Objavi(int id, [FromBody] ObjavaCUDto ocdto, [FromUri] string sid)
        {
            try
            {
                SesijeProvajder.OtvoriSesiju();

                if (!ProvajderPodatakaKorisnika.SesijaValidna(sid))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent("Sesija istekla")
                    });
                }

                if (!ValidatorPrivilegija.KorisnikImaPrivilegiju(sid, ValidatorPrivilegija.UserPrivilegies.PracenjeKorisnika))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                    {
                        Content = new StringContent("Nemate privilegiju")
                    });
                }

                ObjavaCUDto o = ProvajderPodatakaObjava.Objavi(id, ocdto);

                if (o == null)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent("Fakultet nije pronadjen")
                    });
                }

                return(o);
            }
            catch (Exception e)
            {
                if (e is HttpResponseException)
                {
                    throw e;
                }
                DnevnikIzuzetaka.Zabelezi(e);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent("InternalError: " + e.Message)
                });
            }
            finally
            {
                SesijeProvajder.ZatvoriSesiju();
            }
        }
Esempio n. 3
0
        public static ObjavaCUDto UserNewPost(int userId, ObjavaCUDto post)
        {
            RestRequest request = new RestRequest(Method.POST);

            request.Resource = "objave/objavi";
            request.AddParameter("id", userId, ParameterType.QueryString);
            request.AddObject(post);


            ApiResponse <ObjavaCUDto> response = Execute <ObjavaCUDto>(request);

            if (!(response.HttpStatusCode == HttpStatusCode.OK || response.HttpStatusCode == HttpStatusCode.Redirect))
            {
                throw new Exception("UserNewPost: Error" + "\nServerResponse: " + response.ErrorResponse + "\nHttpStatus: "
                                    + response.HttpStatusCode);
            }

            return(response.ResponseObject);
        }
        public static ObjavaCUDto Objavi(int id, ObjavaCUDto ocudto)
        {
            ISession s  = SesijeProvajder.Sesija;
            Korisnik ko = ProvajderPodatakaKorisnika.VratiKorisnika(id);

            if (ko == null)
            {
                return(null);
            }

            if (ko.TipNaloga.IdTip != 5)
            {
                return(null);
            }

            Objava o;

            if (ko.Objava != null)
            {
                o = ko.Objava;
            }
            else
            {
                o = NapraviObjavu(ko);
            }

            List <Menza> menze = s.Query <Menza>().Select(k => k).ToList();
            Menza        m     = menze.Find(x => x.IdMenza == ocudto.IdLokacije);

            o.TekstObjave = ocudto.TekstObjave;
            o.Lokacija    = m;
            o.DatumObjave = DateTime.Now;


            s.Save(o);
            s.Flush();

            return(ocudto);
        }