public static void UpdateImage(POPImage UpdateImg) { if (IsNotNull(UpdateImg)) { if (ExistInRecord(UpdateImg)) { DbAccessHandler.DbContext.Entry(UpdateImg).State = EntityState.Modified; DbAccessHandler.DbContext.SaveChanges(); } } }
public static bool IsNotNull(POPImage image) { if (image != null) { return(true); } else { return(false); } }
public static void RemoveImage(POPImage DeleteImg) { if (IsNotNull(DeleteImg)) { if (ExistInRecord(DeleteImg)) { DbAccessHandler.DbContext.POPImages.Remove(DeleteImg); DbAccessHandler.DbContext.SaveChanges(); } } }
public static POPImage GetPaymentPopImage(Payment pay) { POPImage img = null; if (PaymentServices.IsNotNull(pay)) { var imgs = (from i in DbAccessHandler.DbContext.POPImages where i.PaymentId == pay.Id select i).ToList(); if (imgs.Count() > 0) { img = imgs.First(); } } return(img); }
public static void AddImage(POPImage NewImg) { if (IsNotNull(NewImg)) { if (!ExistInRecord(NewImg)) { if (PaymentServices.IsNotNull(NewImg.Payment)) { DbAccessHandler.DbContext.Entry(NewImg.Payment).State = EntityState.Unchanged; DbAccessHandler.DbContext.POPImages.Add(NewImg); DbAccessHandler.DbContext.SaveChanges(); } } } }
//Get public ActionResult ConfirmPayment(String Id) { Payment pay = PaymentServices.GetPaymentById(Id); if (pay.Confirmed == false) { POPImage img = PopImageServices.GetPaymentPopImage(pay); PaymentDetails details = new PaymentDetails { PaymentId = pay.Id, Amount = pay.Amount, DonorName = pay.DonationPack.Donor.BankAccountOwner.FullName, RecipientAccountNumber = pay.DonationPack.Ticket.TicketHolder.AccountNumber, Date = pay.CreationDate.ToShortDateString(), POPimage = img.Image }; return(PartialView("_ConfirmPayment", details)); } else { return(RedirectToAction("Welcome", "Home")); } }
public ActionResult UploadPaymentInfo(HttpPostedFileBase image) { if (image != null) { using (var db = new ApplicationDbContext()) { var userId = User.Identity.GetUserId(); var AppUser = db.Users.Find(userId); BankAccount UserBankAccount = BankAccountServices.GetUserBankAccount(AppUser); var outgoingdonations = (from d in db.Donations where d.DonorId == UserBankAccount.Id && d.IsOpen == false select d); Donation donation = null; if (outgoingdonations.Count() == 1) { donation = outgoingdonations.First(); } Payment NewPay = new Payment { DonationPack = donation, CreationDate = DateTime.Now, Confirmed = false, }; db.Payments.Add(NewPay); POPImage PopImg = new POPImage(); PopImg.Payment = NewPay; PopImg.Image = new byte[image.ContentLength]; image.InputStream.Read(PopImg.Image, 0, image.ContentLength); db.POPImages.Add(PopImg); db.SaveChanges(); } return(RedirectToAction("Welcome", "Home")); } else { return(HttpNotFound("Something went wrong")); } }
public static bool ExistInRecord(POPImage image) { var test = DbAccessHandler.DbContext.POPImages.Find(image.Id); return(IsNotNull(test)); }