public ActionResult EditReceipt(string recpId) { if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOnPage", "Account"); var scope = ObjectScopeProvider1.GetNewObjectScope(); if (CheckAdminauthorization(scope, User.Identity.Name)) { List<Receipt> receipts = (from c in scope.GetOqlQuery<Receipt>().ExecuteEnumerable() where c.ReceiptNumber.ToLower().Equals(recpId.ToLower()) select c).ToList(); if (receipts.Count > 0) { LoadReceiptValuesFromDb(scope); var receipt = receipts[0]; switch (receipt.ReceiptType) { case ReceiptType.GeneralReceipt: { var model = new RegularReceiptModels { Address = receipt.Address, Address2 = receipt.Address2, Contact = receipt.Contact, DateReceived = receipt.DateReceived, DonationAmount = Convert.ToDouble(receipt.DonationAmount), DonationAmountinWords = receipt.DonationAmountinWords, Email = receipt.Email, City = receipt.City, FirstName = receipt.FirstName, LastName = receipt.LastName, Mi = receipt.Mi, ReceiptNumber = receipt.ReceiptNumber, State = receipt.State, ZipCode = receipt.ZipCode, IssuedDate = receipt.IssuedDate }; ViewData["PostAction"] = "UpdateRegularReceipt"; ViewData["selectedModeOfPayment"] = receipt.ModeOfPayment.ToString(); ViewData["selectedDonationReceivedBy"] = receipt.DonationReceiver.Username; return View("EditRegularReceipt", model); } case ReceiptType.RecurringReceipt: { var model = new RecurringReceipt { Address = receipt.Address, Address2 = receipt.Address2, Contact = receipt.Contact, Email = receipt.Email, ReceiptNumber = receipt.ReceiptNumber, City = receipt.City, FirstName = receipt.FirstName, LastName = receipt.LastName, DonationAmountinWords = receipt.DonationAmountinWords, Mi = receipt.Mi, State = receipt.State, ZipCode = receipt.ZipCode, IssuedDate = receipt.IssuedDate, RecurrenceAmount = receipt.RecurringDetails.Select(m => m.Amount).ToList().ToArray(), RecurrenceDates = receipt.RecurringDetails.Select(m => m.DueDate).ToList().ToArray(), RecurrenceModeofPayment = receipt.RecurringDetails.Select(m => m.ModeOfPayment.ToString()).ToList().ToArray() }; List<RecurrenceData> recurrenceData = receipt.RecurringDetails.Select(rd => new RecurrenceData { Amount = rd.Amount, Date = rd.DueDate.ToString("MM/dd/yyy"), ModeOfPayment = rd.ModeOfPayment.ToString() }).ToList(); ViewData["RecurringDetails"] = recurrenceData; ViewData["PostAction"] = "UpdateRecurringReceipt"; ViewData["selectedModeOfPayment"] = receipt.ModeOfPayment.ToString(); ViewData["selectedDonationReceivedBy"] = receipt.DonationReceiver.Username; return View("EditRecurringReceipt", model); } case ReceiptType.MerchandiseReceipt: { var model = new MerchandiseReceipt { Address = receipt.Address, Address2 = receipt.Address2, Contact = receipt.Contact, DateReceived = receipt.DateReceived, Email = receipt.Email, ReceiptNumber = receipt.ReceiptNumber, MerchandiseItem = receipt.MerchandiseItem, Value = Convert.ToDouble(receipt.FmvValue), City = receipt.City, FirstName = receipt.FirstName, LastName = receipt.LastName, Mi = receipt.Mi, Quanity = receipt.Quantity, State = receipt.State, ZipCode = receipt.ZipCode, IssuedDate = receipt.IssuedDate }; ViewData["selectedDonationReceivedBy"] = receipt.DonationReceiver.Username; ViewData["PostAction"] = "UpdateMerchandiseReceipt"; return View("EditMerchandiseReceipt", model); } case ReceiptType.ServicesReceipt: { var model = new ServicesReceipt { Address = receipt.Address, Address2 = receipt.Address2, Contact = receipt.Contact, DateReceived = receipt.DateReceived, Email = receipt.Email, ReceiptNumber = receipt.ReceiptNumber, HoursServed = receipt.HoursServed, City = receipt.City, FirstName = receipt.FirstName, FmvValue = Convert.ToDouble(receipt.FmvValue), LastName = receipt.LastName, Mi = receipt.Mi, RateperHour = Convert.ToDouble(receipt.RatePerHrOrDay), IssuedDate = receipt.IssuedDate, ServiceType = receipt.ServiceType, State = receipt.State, ZipCode = receipt.ZipCode }; ViewData["selectedDonationReceivedBy"] = receipt.DonationReceiver.Username; ViewData["PostAction"] = "UpdateServicesReceipt"; return View("EditServicesReceipt", model); } } } ViewData["Status"] = "The receipt not found for the given id."; return View("Status"); } ViewData["Status"] = "You are not authorized to do this operation"; return View("PartialViewStatus"); }
public ActionResult RegularReceipt(RegularReceiptModels model) { if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOn", "Account"); var scope = ObjectScopeProvider1.GetNewObjectScope(); if (Checkauthorization(scope, User.Identity.Name)) { if (model.SignatureImage != null) { var donationReceiver = (from c in scope.GetOqlQuery<User>().ExecuteEnumerable() where c.IsheDonationReceiver.Equals(true) && c.Username.Equals(Request.Form["CmbDonationReceivedBy"]) select c).ToList(); if (donationReceiver.Count > 0) { scope.Transaction.Begin(); var receivedTime = Convert.ToDateTime(model.DateReceived); var receipt = new Receipt { Address = model.Address, Address2 = model.Address2, Contact = model.Contact, ReceiptNumber = model.ReceiptNumber, DonationAmount = model.DonationAmount.ToString(), DonationAmountinWords = model.DonationAmountinWords, DonationReceiver = donationReceiver[0], Email = model.Email, DateReceived = receivedTime, FirstName = model.FirstName, ReceiptType = ReceiptType.GeneralReceipt, City = model.City, LastName = model.LastName, Mi = model.Mi, State = model.State, ZipCode = model.ZipCode, IssuedDate = model.IssuedDate }; switch (Request.Form["cmbModeOfPayment"]) { case "Cash": { receipt.ModeOfPayment = ModeOfPayment.Cash; break; } case "Cheque": { receipt.ModeOfPayment = ModeOfPayment.Cheque; break; } case "Mobile": { receipt.ModeOfPayment = ModeOfPayment.Mobile; break; } case "Goods": { receipt.ModeOfPayment = ModeOfPayment.Goods; break; } case "Online": { receipt.ModeOfPayment = ModeOfPayment.Online; break; } } // saving image here try { var signature = new SignatureImage { Filename = model.SignatureImage.FileName }; Stream fileStream = model.SignatureImage.InputStream; int fileLength = model.SignatureImage.ContentLength; signature.Filedata = new byte[fileLength]; fileStream.Read(signature.Filedata, 0, fileLength); signature.MimeType = model.SignatureImage.ContentType; signature.ID = Guid.NewGuid(); receipt.SignatureImage = signature; } catch { } scope.Add(receipt); scope.Transaction.Commit(); ViewData["ReceiptID"] = receipt.ReceiptNumber; return View("Printoptions"); } } LoadReceiptValuesFromDb(scope); var modeofpayments = new List<string> { "Cash", "Cheque", "Online", "Mobile" }; ViewData["modeOfPayment"] = modeofpayments; ViewData["PostAction"] = "RegularReceipt"; ViewData["selectedModeOfPayment"] = Request.Form["cmbModeOfPayment"]; ViewData["selectedDonationReceivedBy"] = Request.Form["CmbDonationReceivedBy"]; ModelState.AddModelError("SignatureImage", "Please input signature image."); ModelState.AddModelError("", "Unable to generate receipt due to invalid parameter passed."); return View(); } ViewData["Status"] = "You are not authorized to do this operation"; return View("PartialViewStatus"); }
public ActionResult UpdateRegularReceipt(RegularReceiptModels model) { if (!User.Identity.IsAuthenticated) return RedirectToAction("LogOnPage", "Account"); var scope = ObjectScopeProvider1.GetNewObjectScope(); if (CheckAdminauthorization(scope, User.Identity.Name)) { var donationReceiver = (from c in scope.GetOqlQuery<User>().ExecuteEnumerable() where c.IsheDonationReceiver.Equals(true) && c.Username.Equals(Request.Form["CmbDonationReceivedBy"]) select c).ToList(); if (donationReceiver.Count > 0) { List<Receipt> receipts = (from c in scope.GetOqlQuery<Receipt>().ExecuteEnumerable() where c.ReceiptNumber.ToLower().Equals(model.ReceiptNumber.ToLower()) select c).ToList(); if (receipts.Count > 0) { scope.Transaction.Begin(); var receivedTime = Convert.ToDateTime(model.DateReceived); var receipt = receipts[0]; receipt.Address = model.Address; receipt.Address2 = model.Address2; receipt.Contact = model.Contact; receipt.ReceiptNumber = model.ReceiptNumber; receipt.DonationAmount = model.DonationAmount.ToString(); receipt.DonationAmountinWords = model.DonationAmountinWords; receipt.DonationReceiver = donationReceiver[0]; receipt.Email = model.Email; receipt.DateReceived = receivedTime; receipt.FirstName = model.FirstName; receipt.LastName = model.LastName; receipt.City = model.City; receipt.State = model.State; receipt.City = model.City; receipt.ZipCode = model.ZipCode; receipt.IssuedDate = model.IssuedDate; receipt.ReceiptType = ReceiptType.GeneralReceipt; switch (Request.Form["cmbModeOfPayment"]) { case "Cash": { receipt.ModeOfPayment = ModeOfPayment.Cash; break; } case "Cheque": { receipt.ModeOfPayment = ModeOfPayment.Cheque; break; } case "Mobile": { receipt.ModeOfPayment = ModeOfPayment.Mobile; break; } case "Goods": { receipt.ModeOfPayment = ModeOfPayment.Goods; break; } case "Online": { receipt.ModeOfPayment = ModeOfPayment.Online; break; } } if (model.SignatureImage != null) { // saving image here try { var signature = new SignatureImage { Filename = model.SignatureImage.FileName }; Stream fileStream = model.SignatureImage.InputStream; int fileLength = model.SignatureImage.ContentLength; signature.Filedata = new byte[fileLength]; fileStream.Read(signature.Filedata, 0, fileLength); signature.MimeType = model.SignatureImage.ContentType; signature.ID = Guid.NewGuid(); receipt.SignatureImage = signature; } catch { } } scope.Add(receipt); scope.Transaction.Commit(); ViewData["Status"] = "Updated successfully."; return View("Status"); } } ViewData["Status"] = "Unable to generate receipt due to invalid parameter passed."; return View("Status"); } ViewData["Status"] = "You are not authorized to do this operation"; return View("Status"); }