public static bool UseMeal(MealType type) { if (LoadedCardUser == null) { MUtility.ShowWarrning("Korisnik nije ucitan"); return(false); } try { ObrokNaplataDto o = new ObrokNaplataDto(); o.BrojObroka = 1; o.IdKorisnika = MainController.LoadedCardUser.UserID; o.IdLokacijeIskoriscenja = MSettings.CurrentMensa.MensaID; o.IdTipa = (int)type; Api.UseMeal(o); return(true); } catch (Exception e) { MUtility.ShowException(e); return(false); } }
public static void UseMeal(ObrokNaplataDto m) { RestRequest request = new RestRequest(Method.PUT); request.Resource = "obroci/naplati"; request.AddObject(m); var response = Execute(request); if (!(response.HttpStatusCode == HttpStatusCode.OK || response.HttpStatusCode == HttpStatusCode.Redirect)) { throw new Exception("UseMeal: Obrok nije naplacen." + "\n" + response.ErrorResponse + "\nHttpStatus: " + response.HttpStatusCode); } }
public IHttpActionResult NaplatiObroke([FromBody] ObrokNaplataDto obNapDto, [FromUri] string sid) { int i = 1; 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.ModifikacijaObrok)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent("Nemate privilegiju") }); } while (i <= obNapDto.BrojObroka) { Obrok obrokZaSkidanje = ProvajderPodatakaObroka.ObrokZaSkidanjeOvogTipa(obNapDto.IdKorisnika, obNapDto.IdTipa); if (obrokZaSkidanje != null) { ProvajderPodatakaObroka.PojediObrok(obrokZaSkidanje.IdObroka, obNapDto.IdLokacijeIskoriscenja); ++i; } else { break; } } if (i == 1) { return(Ok("Ne moze se skunuti, nema obroka")); } else { return(Ok("Uspesno je skunuto " + (i - 1).ToString() + " obroka.")); } } 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(); } }