public IHttpActionResult GetPaiment(int id) { var RequestingUser = GetUserFromAuthHeader(ActionContext.Request.Headers.Authorization.Parameter); var payments = db.Paiments.Where(P => P.SenderID == RequestingUser.UserID || P.RecieverID == RequestingUser.UserID); Paiment Paiment = payments.Where(P => P.PaymentID == id).FirstOrDefault(); if (Paiment == null) { return(NotFound()); } return(Ok(Paiment)); }
public IHttpActionResult PostPaiment(Paiment Paiment) { var RequestingUser = GetUserFromAuthHeader(ActionContext.Request.Headers.Authorization.Parameter); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (Paiment.SenderID != RequestingUser.UserID && Paiment.SenderFullName != (RequestingUser.LastName + " " + RequestingUser.FirstName)) { return(Unauthorized()); } Paiment.Date = DateTime.Now; db.Paiments.Add(Paiment); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = Paiment.PaymentID }, Paiment)); }
public async Task <IActionResult> Create(CreatePaiementModel paiment) { if (ModelState.IsValid) { var model = new Paiment(); if (paiment.ActionFrom == "Paiement") { model.StudentID = await stu.GetStudentId(paiment.StudentNumber); model.MonthId = paiment.Period; model.Type = paiment.Type; model.PaidOn = paiment.DateofPaiement; model.Amount = paiment.Amount; Pmt.Add(model); await Pmt.SaveChangesAsync(); return(RedirectToAction("PayHistoric", new RouteValueDictionary( new { Controller = "Paiment", action = "PayHistoric", Id = paiment.StudentID }))); } else { model.StudentID = paiment.StudentID; model.MonthId = paiment.Period; model.Type = paiment.Type; model.PaidOn = paiment.DateofPaiement; model.Amount = paiment.Amount; Pmt.Add(model); await Pmt.SaveChangesAsync(); return(RedirectToAction("PayHistoric", new RouteValueDictionary( new { Controller = "Paiment", action = "PayHistoric", Id = paiment.StudentID }))); } } InitializeDropdownList(paiment.Period, paiment.Type, null, 2); return(View(paiment)); }
public void Add(Paiment p) { context.Add(p); }