public ActionResult UpdateMerchandiseReceipt(MerchandiseReceipt model)
        {
            if (!User.Identity.IsAuthenticated)
                return RedirectToAction("LogOn", "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.MerchandiseItem = model.MerchandiseItem;
                        receipt.FmvValue = model.Value.ToString();
                        receipt.DonationReceiver = donationReceiver[0];
                        receipt.Email = model.Email;
                        receipt.DateReceived = receivedTime;
                        receipt.FirstName = model.FirstName;
                        receipt.Mi = model.Mi;
                        receipt.LastName = model.LastName;
                        receipt.City = model.City;
                        receipt.State = model.State;
                        receipt.ZipCode = model.ZipCode;
                        receipt.Quantity = model.Quanity;
                        receipt.IssuedDate = model.IssuedDate;
                        receipt.ReceiptType = ReceiptType.MerchandiseReceipt;

                        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");
        }
 public ActionResult MerchandiseReceipt()
 {
     if (!User.Identity.IsAuthenticated)
         return RedirectToAction("LogOn", "Account");
     var scope = ObjectScopeProvider1.GetNewObjectScope();
     if (Checkauthorization(scope, User.Identity.Name))
     {
         LoadReceiptValuesFromDb(scope);
         ViewData["PostAction"] = "MerchandiseReceipt";
         ViewData["selectedDonationReceivedBy"] = string.Empty;
         var receiptModel = new MerchandiseReceipt
                               {
                                   ReceiptNumber = Utilities.GenerateReceiptId(),
                                   DateReceived = DateTime.Now,
                                   IssuedDate = DateTime.Now
                               };
         return View(receiptModel);
     }
     ViewData["Status"] = "You are not authorized to do this operation";
     return View("PartialViewStatus");
 }
 public ActionResult MerchandiseReceipt(MerchandiseReceipt 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,
                                       MerchandiseItem = model.MerchandiseItem,
                                       FmvValue = model.Value.ToString(),
                                       DonationReceiver = donationReceiver[0],
                                       Email = model.Email,
                                       DateReceived = receivedTime,
                                       FirstName = model.FirstName,
                                       City = model.City,
                                       LastName = model.LastName,
                                       Mi = model.Mi,
                                       Quantity = model.Quanity,
                                       State = model.State,
                                       ZipCode = model.ZipCode,
                                       IssuedDate = model.IssuedDate,
                                       ReceiptType = ReceiptType.MerchandiseReceipt
                                   };
                 // 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);
         ViewData["PostAction"] = "MerchandiseReceipt";
         ViewData["selectedDonationReceivedBy"] = Request.Form["CmbDonationReceivedBy"];
         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 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");
 }