public HttpResponseMessage PostMusterija([FromBody] Komentar kom) { HttpResponseMessage msg = new HttpResponseMessage(); KomentarRepository repo = new KomentarRepository(); try { using (var db = new SystemDBContext()) { kom.PostingTime = DateTime.Now; kom.Id = repo.GetKomentari().Count + 1; db.Komentari.Add(kom); db.SaveChanges(); msg = Request.CreateResponse(HttpStatusCode.Created, kom); msg.Headers.Location = new Uri(Request.RequestUri + kom.Id.ToString()); return(msg); } } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e)); } }
public void OznaciPregledan(int komentarId) { using (BHaoDataContext context = new BHaoDataContext()) { IKomentarRepository repo = new KomentarRepository(context); var komentar = repo.Get(komentarId); komentar.KomentarPregledan = true; repo.Update(komentar); } }
public void UkloniKomentar(int komentarId) { using (BHaoDataContext context = new BHaoDataContext()) { IKomentarRepository repo = new KomentarRepository(context); var komentar = repo.Get(komentarId); komentar.isDeleted = true; repo.Update(komentar); PosaljiPoruku(context, komentar.KomentatorId, komentar.AukcijaId, komentar.TextKomentara); } }
public KomentarDTO[] GetKomentari(bool isPregledan) { try { using (BHaoDataContext context = new BHaoDataContext()) { IKomentarRepository repo = new KomentarRepository(context); var komentari = repo.GetKomentariPregled(isPregledan); return(komentari); } } catch (Exception ex) { throw new FaultException(ex.Message); } }
public HttpResponseMessage GetKomentar(int startLocation) { HttpResponseMessage msg; KomentarRepository repo = new KomentarRepository(); try { List <Komentar> list = repo.GetKomentari().FindAll(x => x.DriveID == startLocation); msg = Request.CreateResponse(HttpStatusCode.OK, list); } catch (Exception e) { msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"Error - {e.Message}"); } return(msg); }
public HttpResponseMessage GetKomentar(string sortType) { HttpResponseMessage msg; VoznjaRepository repo = new VoznjaRepository(); KomentarRepository lrepo = new KomentarRepository(); List <Voznja> voznje = repo.GetVoznje(); List <Komentar> komentari = new KomentarRepository().GetKomentari(); List <Voznja> temp = new List <Voznja>(); try { if (sortType == "Date") { voznje = voznje.OrderBy(x => x.TimeOfReservation).ToList(); } else if (sortType == "Grade") { //voznje.Sort((a, b) => (lrepo.GetOneKomentar(a.StartPointID.Value).Grade.CompareTo(lrepo.GetOneKomentar(b.StartPointID.Value).Grade))); komentari = komentari.OrderByDescending(x => x.Grade).ToList(); komentari.ForEach(x => { voznje.ForEach(c => { if (x.Id == c.CommentID) { temp.Add(c); } }); }); voznje = temp; } msg = Request.CreateResponse(HttpStatusCode.OK, voznje); } catch (Exception e) { msg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"Error - {e.Message}"); } return(msg); }