public ActionResult GenerateInvoice(int?id, string email)
        {
            if (User.IsInRole("Business Customer"))
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                CustomerOrder order        = db.CustomerOrders.Find(id);
                var           orderDetails = db.Orderedproducts.Where(x => x.CustomerOrderId == id);

                order.Products = orderDetails.ToList();
                if (order == null)
                {
                    return(HttpNotFound());
                }
                ResponseModel.SendSimpleMessage(email);
                return(View(order));
            }

            else
            {
                return(RedirectToAction("Index", "ShoppingCart"));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public ActionResult Complete(int id, string email)
        {
            bool isValid = db.CustomerOrders.Any(
                o => o.Id == id &&
                o.CustomerUserName == User.Identity.Name
                );

            if (isValid)
            {
                ResponseModel.SendSimpleMessage(email);
                return(View(id));
            }
            else
            {
                var order = new CustomerOrder();
                order = db.CustomerOrders.Find(id);
                db.CustomerOrders.Remove(order);
                return(View("Error"));
            }
        }
        public ActionResult ChangeStatus(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Document document = db.Documents.Find(id);

            if (document == null)
            {
                return(HttpNotFound());
            }
            if (document.DocumentStatus == "Archived")
            {
                return(RedirectToAction("Index"));
            }
            try
            {
                if (document.DocumentStatus == "Draft")
                {
                    //checks for a document with that title and is active exists
                    var check = db.Documents.SingleOrDefault(o => o.DocTitle == document.DocTitle && o.DocumentStatus == "Active");
                    if (check != null)
                    {
                        //if this isnt null set the checked value to archived and the new document to active
                        check.DocumentStatus    = "Archived";
                        document.DocumentStatus = "Active";
                        document.ActivationDate = DateTime.Now;
                    }
                    else
                    {
                        //if this was null set the new document to active
                        document.DocumentStatus = "Active";
                        document.ActivationDate = DateTime.Now;
                    }
                    if (ModelState.IsValid)
                    {
                        db.Entry(document).State = EntityState.Modified;
                        db.SaveChanges();
                        ViewBag.Message = "Status of document changed to active";
                        var email = document.Distributee;
                        ResponseModel.SendSimpleMessage(email);
                        return(RedirectToAction("Index"));
                    }
                }
                else if (document.DocumentStatus == "Active")
                {
                    //creates the new document from the values of its parent document
                    var newdocument = new Document();
                    newdocument.DocTitle       = document.DocTitle;
                    newdocument.RevisionNumber = document.RevisionNumber + 1;
                    newdocument.DocumentAuthor = document.DocumentAuthor;
                    newdocument.DocumentStatus = "Draft";
                    //sets the dates to right now and sets the file path to none (an attachment can be added from the details page once it is created)
                    newdocument.CreationDate   = DateTime.Now;
                    newdocument.ActivationDate = DateTime.Now;
                    newdocument.FilePath       = "none";
                    newdocument.Distributee    = document.Distributee;

                    //adds the new document to the database if the model state is valid if not it will return this page without submitting
                    if (ModelState.IsValid)
                    {
                        db.Documents.Add(newdocument);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    return(View(document));
                }
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
            return(View(document));
        }