public ActionResult Create([Bind(Include = "Name, Detail, ContactNumber, EmailAddress")] Restaurant restaurant)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Restaurant.Add(restaurant);
                    db.SaveChanges();

                    restaurant.DateAdded = DateTime.Now;
                    db.SaveChanges();

                    restaurant.ServiceProviderStatus = (int?)Common.ServiceProviderStatusEnum.Inactive;
                    restaurant.PartnerUserId         = int.Parse(DataSecurityTripleDES.GetPlainText(SessionManager.GetContextSessionLoggedUserID()));
                    restaurant.LastUpdated           = DateTime.Now;
                    db.SaveChanges();

                    return(RedirectToAction("AddAddress", "Profile", new
                    {
                        ownerType = DataSecurityTripleDES.GetEncryptedText((int)Common.OwnerTypeEnum.ServiceProvider),
                        ownerId = DataSecurityTripleDES.GetEncryptedText(restaurant.Id)
                    }));
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return(View(restaurant));
        }
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            SessionManager.RegisterSessionActivity();

            if (ModelState.IsValid)
            {
                User          anActiveOrBlockedUser = null;
                CEUserManager ceUserManager         = new CEUserManager();
                anActiveOrBlockedUser = ceUserManager.GetSigningUserByEmail(model.Email);

                if (anActiveOrBlockedUser == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                string longTicks = DateTime.Now.Ticks.ToString(),
                       code      = DataSecurityTripleDES.GetEncryptedText(longTicks);

                using (CraveatsDbContext craveatsDbContext = new CraveatsDbContext())
                {
                    User anUser = craveatsDbContext.User.First(u => u.Id == anActiveOrBlockedUser.Id);

                    anUser.ResetCode       = longTicks;
                    anUser.ResetCodeExpiry = DateTime.Now.AddDays(1);
                    anUser.ResetCodeSentAt = DateTime.Now;

                    anUser.LastUpdated = DateTime.Now;

                    craveatsDbContext.SaveChanges();
                }

                var callbackUrl = Url.Action("ResetPassword", "Login", new { userId = DataSecurityTripleDES.GetEncryptedText(anActiveOrBlockedUser.Id), code = code }, protocol: Request.Url.Scheme);

                StringBuilder sbSubject   = new StringBuilder("Craveats reset password request"),
                              sbEmailBody = new StringBuilder("<p>Dear [FullName],</p><p>We have received a request that you would like to reset your account password with us." +
                                                              "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a></p><p>Thank you.</p><p>Craveats</p>");

                CommunicationServiceProvider.SendOutgoingNotification(
                    new MailAddress(
                        anActiveOrBlockedUser.EmailAddress,
                        string.Format("{0}{1}{2}", anActiveOrBlockedUser?.FirstName, " ", anActiveOrBlockedUser?.Surname).Trim()),
                    sbSubject.ToString(),
                    sbEmailBody.Replace("[FullName]",
                                        string.Format("{0}{1}{2}", anActiveOrBlockedUser?.FirstName, " ", anActiveOrBlockedUser?.Surname).Trim()).ToString());

                return(RedirectToAction("ForgotPasswordConfirmation", "Login"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        internal void SaveUserDetail(UserDTO userDTO)
        {
            try
            {
                using (CraveatsDbContext craveatsDbContext = new CraveatsDbContext())
                {
                    int  userId = int.Parse(DataSecurityTripleDES.GetPlainText(userDTO.Id));
                    User anUser = craveatsDbContext.User.FirstOrDefault(u => u.Id == userId);

                    anUser = EntityDTOHelper.MapToEntity <UserDTO, User>(userDTO, anUser);

                    anUser.LastUpdated = DateTime.Now;
                    craveatsDbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public ActionResult ResetPassword(ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            User          anActiveOrBlockedUser = null;
            CEUserManager ceUserManager = new CEUserManager();
            int           userIDFromRequest = 0;
            string        plainCode = null, errorInTranslation = string.Empty;

            try
            {
                userIDFromRequest = int.Parse(DataSecurityTripleDES.GetPlainText(model.UserId));
                plainCode         = DataSecurityTripleDES.GetPlainText(model.Code);

                DateTime minExpiry = DateTime.Now;

                using (CraveatsDbContext craveatsDbContext = new CraveatsDbContext())
                {
                    anActiveOrBlockedUser = craveatsDbContext.User.First(u => u.Id == userIDFromRequest && u.ResetCode == plainCode && (!u.ResetCodeExpiry.HasValue || u.ResetCodeExpiry >= minExpiry));
                    anActiveOrBlockedUser.ResetCodeExpiry = DateTime.Now;
                    anActiveOrBlockedUser.ResetCode       = null;

                    anActiveOrBlockedUser.Password = new SHA1HashProvider().SecureSHA1(model.Password.Trim());

                    anActiveOrBlockedUser.LastUpdated = DateTime.Now;

                    craveatsDbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
            }

            return(RedirectToAction("ResetPasswordConfirmation", "Account"));
        }
        public ActionResult Create([Bind(Include = "Name, Brief, Detail, UnitPrice")] RestaurantMenu restaurantMenu, string ownerType = null, string ownerId = null)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //int.Parse(DataSecurityTripleDES.GetPlainText(SessionManager.GetContextSessionLoggedUserID()));
                    db.RestaurantMenu.Add(restaurantMenu);
                    db.SaveChanges();

                    restaurantMenu.DateAdded = DateTime.Now;
                    db.SaveChanges();

                    restaurantMenu.ServiceStatus = (int?)Common.ServiceStatusEnum.Active;
                    restaurantMenu.OwnerId       = int.Parse(
                        DataSecurityTripleDES.GetPlainText(
                            ownerId));
                    restaurantMenu.OwnerType   = (int)Common.OwnerTypeEnum.ServiceProvider;
                    restaurantMenu.IsTaxable   = true;
                    restaurantMenu.TaxRate     = 13m;
                    restaurantMenu.LastUpdated = DateTime.Now;
                    db.SaveChanges();

                    Restaurant ownerRestaurant = db.Restaurant.FirstOrDefault(u => u.Id == restaurantMenu.OwnerId &&
                                                                              (u.ServiceProviderStatus.HasValue &&
                                                                               u.ServiceProviderStatus.Value == (int)Common.ServiceProviderStatusEnum.Inactive) &&
                                                                              u.AddressId.HasValue);
                    if (ownerRestaurant != null)
                    {
                        ownerRestaurant.ServiceProviderStatus = (int)Common.ServiceProviderStatusEnum.Active;
                        db.SaveChanges();
                    }

                    return(RedirectToAction("Index", new { ownerType = ownerType, ownerId = ownerId }));
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return(View(restaurantMenu));
        }
        public ActionResult FinalisePayment(string stripeToken)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var cart = Session["cart"] as CraveatsCart;



                    //long? total = (long)order.OrderTotal;
                    // Set your secret key: remember to change this to your live secret key in production
                    // See your keys here: https://dashboard.stripe.com/account/apikeys
                    StripeConfiguration.SetApiKey("sk_test_Rg2BSmdAQkVhLwSdOZyTqHGZ");

                    // Token is created using Checkout or Elements!
                    // Get the payment token submitted by the form:
                    //var token = CraveatsCart.Token; // Using ASP.NET MVC

                    long chargeAmount = (long)(decimal.Parse(CommonUtility.DoFormat((cart.CartTotalBeforeTax + cart.CartTotalTax))) * 100);
                    var  options      = new ChargeCreateOptions
                    {
                        Amount      = chargeAmount,
                        Currency    = "cad",
                        Description = "Order Payment 20181129",
                        SourceId    = stripeToken
                    };
                    var    service = new ChargeService();
                    Charge charge  = service.Create(options);

                    if (charge.Status == "succeeded")
                    {
                        DAL.Order newOrder = new DAL.Order()
                        {
                            DateCreated   = DateTime.Now,
                            DiscountTotal = 0.0m,
                            OrderStatus   = (int)OrderStatusEnum.Paid,
                            OrderTotal    = cart.CartTotalBeforeTax,
                            SessionId     = int.Parse(DataSecurityTripleDES.GetPlainText(SessionManager.GetContextSessionID())),
                            TaxTotal      = cart.CartTotalTax,
                            UserId        = int.Parse(DataSecurityTripleDES.GetPlainText(cart.OwnerId))
                        };
                        db.Order.Add(newOrder);
                        db.SaveChanges();

                        foreach (RestaurantMenuCartDTO restaurantMenuCartDTO in cart.Items)
                        {
                            db.OrderDetail.Add(new OrderDetail()
                            {
                                IsTaxable        = restaurantMenuCartDTO.IsTaxable,
                                OrderId          = newOrder.Id,
                                ServiceId        = int.Parse(DataSecurityTripleDES.GetPlainText(restaurantMenuCartDTO.Id)),
                                ServiceOwnerId   = int.Parse(DataSecurityTripleDES.GetPlainText(restaurantMenuCartDTO.ServiceOwnerId)),
                                ServiceOwnerType = int.Parse(DataSecurityTripleDES.GetPlainText(restaurantMenuCartDTO.ServiceOwnerType)),
                                TaxRate          = restaurantMenuCartDTO.TaxRate,
                                UnitPrice        = restaurantMenuCartDTO.UnitPrice,
                                Quantity         = restaurantMenuCartDTO.Quantity,
                                Name             = restaurantMenuCartDTO.Name,
                                Detail           = restaurantMenuCartDTO.Detail
                            });
                            db.SaveChanges();
                        }

                        db.OrderPayment.Add(new OrderPayment()
                        {
                            DateProcessed          = DateTime.Now,
                            GatewayResponseCode    = charge.Id,
                            GatewayResponseVerbose = charge.Status,
                            TotalAmount            = (decimal)(charge.Amount / 100.00)
                        });
                        db.SaveChanges();

                        cart            = null;
                        Session["cart"] = null;

                        return(View("Success", new WebApplication.Models.ViewModel.OrderConfirmationDTO()
                        {
                            Id = DataSecurityTripleDES.GetEncryptedText(newOrder.Id),
                            StatusMessage = "success"
                        }));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Unable to accept charges. Try again, and if the problem persists please review your card detail with your bank.");
                    }
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return(View());
        }