public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                CEUserManager    ceUserManager         = new CEUserManager();
                SHA1HashProvider sHA1HashProvider      = new SHA1HashProvider();
                User             anActiveOrBlockedUser = ceUserManager.GetSigningUserByEmail(model.Email);

                if (anActiveOrBlockedUser != null && sHA1HashProvider.CheckHashSHA1(model.Password, anActiveOrBlockedUser.Password, 8))
                {
                    UserDTO userDTO = EntityDTOHelper.GetEntityDTO <User, UserDTO>(anActiveOrBlockedUser);
                    AuthenticatedUserInfo authenticatedUserInfo = new AuthenticatedUserInfo(userDTO);

                    ceUserManager.SignInUser(HttpContext, string.Format("{0}", authenticatedUserInfo.FullName), false);

                    Session["loggeduser"] = authenticatedUserInfo;

                    SessionManager.RegisterSessionActivity(loggedInAt: DateTime.Now);

                    return(this.RedirectToLocal(returnUrl));
                }

                ModelState.AddModelError(string.Empty, "Login attempt failed.");
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e);
            }
            return(this.View(model));
        }
예제 #2
0
        public ActionResult EditDinerProfile(string identifier)
        {
            if (Session != null && Session.Contents != null)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;

                if (authenticatedUserInfo != null)
                {
                    UserDTO userDTO = EntityDTOHelper.GetEntityDTO <DAL.User, UserDTO>(new CEUserManager().FindById(
                                                                                           int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId))));

                    CraveatsDinerViewModel craveatsDinerViewModel = null;

                    if (((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.CraveatsDiner))
                    {
                        craveatsDinerViewModel = new CraveatsDinerViewModel()
                        {
                            Id            = userDTO.Id,
                            ContactNumber = userDTO.ContactNumber,
                            Email         = userDTO.EmailAddress,
                            FirstName     = userDTO.FirstName,
                            Surname       = userDTO.Surname,
                            Role          = Common.UserTypeEnum.CraveatsDiner.GetDescription()
                        };
                    }
                    return(View("EditDinerProfile", craveatsDinerViewModel));
                }
            }
            return(View("Error"));
        }
        public ActionResult AddToCart(string id)
        {
            DAL.RestaurantMenu    restaurantMenu = menuModel.find(int.Parse(DataSecurityTripleDES.GetPlainText(id)));
            RestaurantMenuCartDTO thisMenuDTO    = EntityDTOHelper.GetEntityDTO <RestaurantMenu, RestaurantMenuCartDTO>(restaurantMenu);

            DAL.Restaurant restaurant = db.Restaurant.Find(restaurantMenu.OwnerId);

            thisMenuDTO.ServiceOwnerName = restaurant.Name;
            thisMenuDTO.ServiceOwnerId   = DataSecurityTripleDES.GetEncryptedText(restaurant.Id);
            thisMenuDTO.ServiceOwnerType = DataSecurityTripleDES.GetEncryptedText((int)OwnerTypeEnum.ServiceProvider);

            DAL.Address address = db.Address.Find(restaurant.AddressId);
            if (address != null)
            {
                AddressDTO addressDTO = EntityDTOHelper.GetEntityDTO <DAL.Address, AddressDTO>(address);
                thisMenuDTO.ServiceOwnerAddressDetail = addressDTO.GetAddressString(true);
            }

            if (thisMenuDTO != null)
            {
                thisMenuDTO.Quantity = 1;

                CraveatsCart craveatsCart = (Session["cart"] == null) ? new CraveatsCart(SessionManager.GetContextSessionLoggedUserID()) : (Session["cart"] as CraveatsCart);
                craveatsCart.AddToCart(thisMenuDTO);

                Session["cart"] = craveatsCart;
            }

            return(RedirectToAction("Index"));
        }
예제 #4
0
        public ActionResult PartnerRestaurant(PartnerRestaurantViewModel model)
        {
            if (Session != null && Session.Contents != null)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;

                if (authenticatedUserInfo != null)
                {
                    UserDTO userDTO = EntityDTOHelper.GetEntityDTO <DAL.User, UserDTO>(new CEUserManager().FindById(
                                                                                           int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId))));

                    PartnerRestaurantViewModel partnerRestaurantViewModel = null;

                    if (((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.PartnerRestaurant))
                    {
                        partnerRestaurantViewModel = new PartnerRestaurantViewModel()
                        {
                            Id            = userDTO.Id,
                            ContactNumber = userDTO.ContactNumber,
                            Email         = userDTO.EmailAddress,
                            FirstName     = userDTO.FirstName,
                            Surname       = userDTO.Surname,
                            Role          = Common.UserTypeEnum.PartnerRestaurant.GetDescription()
                        };
                    }

                    if ((userDTO.AddressId ?? "").Length > 0)
                    {
                        DataProvider dataProvider = new DataProvider();

                        DAL.Address anAddress = dataProvider.FindAddressById(
                            int.Parse(DataSecurityTripleDES.GetPlainText(userDTO.AddressId)));

                        AddressViewModel addressViewModel = EntityDTOHelper.GetEntityDTO <DAL.Address, AddressViewModel>(anAddress);

                        if (anAddress != null)
                        {
                            DAL.Region region = dataProvider.FindRegionById(anAddress.RegionId ?? 0);

                            if (region != null)
                            {
                                addressViewModel.RegionAlias = region.RegionAlias;
                                addressViewModel.RegionId    = DataSecurityTripleDES.GetEncryptedText(region.Id);
                            }

                            partnerRestaurantViewModel.Addresses = new List <AddressViewModel>()
                            {
                                addressViewModel
                            };
                        }
                    }

                    return(View("PartnerRestaurant", partnerRestaurantViewModel));
                }
            }

            return(View("Error"));
        }
        public ActionResult Remove(string id)
        {
            RestaurantMenuCartDTO thisMenuDTO = EntityDTOHelper.GetEntityDTO <RestaurantMenu, RestaurantMenuCartDTO>(menuModel.find(int.Parse(DataSecurityTripleDES.GetPlainText(id))));

            if (thisMenuDTO != null && Session["cart"] != null)
            {
                CraveatsCart craveatsCart = Session["cart"] as CraveatsCart;
                craveatsCart.RemoveItem(id);

                Session["cart"] = craveatsCart;
            }

            return(RedirectToAction("Index"));
        }
        internal async Task <UserDTO> FindByIdAsync(int loggedUserId)
        {
            UserDTO userDTO = null;

            try
            {
                using (CraveatsDbContext craveatsDbContext = new CraveatsDbContext())
                {
                    User user = await craveatsDbContext.User.FindAsync(loggedUserId);

                    userDTO = EntityDTOHelper.GetEntityDTO <User, UserDTO>(user);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
            }
            return(userDTO);
        }
예제 #7
0
        // GET: OrderHistory
        public ActionResult Index(string id)
        {
            var viewModel = new OrderOrderDetailIndexData();

            int userId = int.Parse(
                DataSecurityTripleDES.GetPlainText(
                    SessionManager.GetContextSessionLoggedUserID()));

            List <Order> userOrders = db.Order.Where(u =>
                                                     u.UserId == userId).OrderByDescending(
                u => u.LastUpdated ?? u.DateCreated).ToList();

            List <OrderHistoryDTO> orderHistoryDTOs = new List <OrderHistoryDTO>();

            foreach (Order anOrder in userOrders)
            {
                orderHistoryDTOs.Add(EntityDTOHelper.GetEntityDTO <Order, OrderHistoryDTO>(anOrder));
            }
            viewModel.Orders = orderHistoryDTOs;

            if (id != null)
            {
                int?anOrderId = (int?)int.Parse(
                    DataSecurityTripleDES.GetPlainText(id));

                List <OrderDetail> userOrderDetails = db.OrderDetail.Where(u =>
                                                                           u.OrderId == anOrderId).OrderBy(
                    u => u.Id).ToList();

                List <OrderDetailHistoryDTO> orderDetailHistoryDTO = new List <OrderDetailHistoryDTO>();
                foreach (OrderDetail anOrderDetail in userOrderDetails)
                {
                    orderDetailHistoryDTO.Add(EntityDTOHelper.GetEntityDTO <OrderDetail, OrderDetailHistoryDTO>(anOrderDetail));
                }

                ViewBag.OrderId        = id;
                viewModel.OrderDetails = orderDetailHistoryDTO;
            }

            return(View(viewModel));
        }
예제 #8
0
        public ActionResult ProfileView(ProfileViewModel model)
        {
            model = new ProfileViewModel();

            if (Session != null && Session.Contents != null)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;

                if (authenticatedUserInfo != null)
                {
                    UserDTO userDTO = EntityDTOHelper.GetEntityDTO <DAL.User, UserDTO>(new CEUserManager().FindById(
                                                                                           int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId))));

                    model.ModelUserType = (Common.UserTypeEnum)userDTO.UserTypeFlag;

                    return(View(model));
                }
            }

            ModelState.AddModelError(string.Empty, "Session has expired");
            return(View("ProfileView", null));
        }
예제 #9
0
        public ActionResult AddAddress(string ownerType = null, string ownerId = null)
        {
            if ((ownerType ?? string.Empty).Length > 0 && (ownerId ?? string.Empty).Length > 0)
            {
                ViewBag.AlterButtonTitle  = true;
                ViewBag.AlteredButtonName = "Next";
            }

            SessionManager.RegisterSessionActivity();

            if (Session != null && Session.Contents != null)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;

                if (authenticatedUserInfo != null)
                {
                    UserDTO userDTO = EntityDTOHelper.GetEntityDTO <DAL.User, UserDTO>(new CEUserManager().FindById(
                                                                                           int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId))));

                    if (((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.CraveatsDiner) ||
                        ((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.PartnerRestaurant))
                    {
                        IEnumerable <string> regionAliases = GetAllRegionAliases();

                        AddressViewModel addressViewModel = new AddressViewModel()
                        {
                            RegionAliases = GenUtil.GetSelectListItems(regionAliases),
                            OwnerId       = ownerId,
                            OwnerType     = ownerType
                        };

                        return(View("AddAddress", addressViewModel));
                    }
                }
            }
            return(View("Error"));
        }
        public ActionResult Register(RegisterViewModel model)
        {
            SessionManager.RegisterSessionActivity();

            // Get all states again
            var roles = GetAllRoles();

            // Set these states on the model. We need to do this because
            // only the selected value from the DropDownList is posted back, not the whole
            // list of states.
            model.Roles = GenUtil.GetSelectListItems(roles);

            // In case everything is fine - i.e. both "Name" and "State" are entered/selected,
            // redirect user to the "Done" page, and pass the user object along via Session
            if (ModelState.IsValid)
            {
                SHA1HashProvider sHA1HashProvider = new SHA1HashProvider();
                if (!ceUserManager.IsRegistered(model.Email))
                {
                    string sha1HashText = sHA1HashProvider.SecureSHA1(model.Password.Trim());
                    int?   newUserID    = ceUserManager.RegisterNew(model.Email, sha1HashText, model.Role);
                    if (newUserID.HasValue)
                    {
                        UserDTO userDTO = new UserDTO()
                        {
                            Id         = DataSecurityTripleDES.GetEncryptedText(newUserID),
                            FirstName  = model.FirstName,
                            Surname    = model.Surname,
                            UserStatus = (int?)UserStatusEnum.Active
                        };

                        ceUserManager.SaveUserDetail(userDTO);

                        StringBuilder sbSubject   = new StringBuilder("Craveats new registrant notification"),
                                      sbEmailBody = new StringBuilder("<p>A new user with the following detail has been registered in the system. " +
                                                                      $"<br/><em>FirstName            </em>: {model.FirstName}" +
                                                                      $"<br/><em>Surname              </em>: {model.Surname}" +
                                                                      $"<br/><em>Email                </em>: {model.Email}" +
                                                                      $"<br/><em>Registration Type    </em>: {model.Role}" +
                                                                      "</p><p>Thank you.</p><p>Craveats</p>");

                        CommunicationServiceProvider.SendOutgoingNotification(
                            new MailAddress(
                                model.Email,
                                string.Format("{0}{1}{2}", model.FirstName, " ", model?.Surname).Trim()),
                            sbSubject.ToString(),
                            sbEmailBody.ToString());

                        User result = ceUserManager.FindByCriteria(email: model.Email, userStatusEnums: new List <int> {
                            (int)UserStatusEnum.Active, (int)UserStatusEnum.Blocked
                        });
                        if (result != null)
                        {
                            userDTO = EntityDTOHelper.GetEntityDTO <User, UserDTO>(result);

                            AuthenticatedUserInfo authenticatedUserInfo = new AuthenticatedUserInfo(userDTO);
                            Session["loggeduser"] = authenticatedUserInfo;

                            SessionManager.RegisterSessionActivity(userID: result.Id, loggedInAt: DateTime.Now);

                            ceUserManager.SignInUser(HttpContext, string.Format("{0}", authenticatedUserInfo.FullName), false);

                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, "An error occurred in reading user data. Please review input and re-try.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "An error occurred in registering new user. Please review input and re-try.");
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Email is registered and cannot be used to create another account.");
                }
            }

            // Something is not right - so render the registration page again,
            // keeping the data user has entered by supplying the model.
            return(View("Register", model));
        }
예제 #11
0
        public ActionResult EditAddress(string id)
        {
            SessionManager.RegisterSessionActivity();

            if (Session != null && Session.Contents != null)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;

                if (authenticatedUserInfo != null)
                {
                    UserDTO userDTO = EntityDTOHelper.GetEntityDTO <DAL.User, UserDTO>(new CEUserManager().FindById(
                                                                                           int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId))));

                    if (((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.CraveatsDiner) ||
                        ((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.PartnerRestaurant))
                    {
                        DataProvider dataProvider = new DataProvider();
                        AddressDTO   addressDTO   = EntityDTOHelper.GetEntityDTO <DAL.Address, AddressDTO>(
                            dataProvider.FindAddressById(int.Parse(DataSecurityTripleDES.GetPlainText(id))));

                        if (addressDTO != null)
                        {
                            RegionDTO regionDTO = addressDTO.RegionId?.Trim().Length <= 0
                                ? null
                                : EntityDTOHelper.GetEntityDTO <DAL.Region, RegionDTO>(
                                dataProvider.FindRegionById(
                                    int.Parse(DataSecurityTripleDES.GetPlainText(addressDTO.RegionId))));

                            if (regionDTO != null)
                            {
                                addressDTO.RegionAlias = regionDTO.RegionAlias;
                                addressDTO.RegionName  = regionDTO.RegionName;
                            }

                            CountryDTO countryDTO = addressDTO.CountryId?.Trim().Length <= 0
                                ? null
                                : EntityDTOHelper.GetEntityDTO <DAL.Country, CountryDTO>(
                                dataProvider.FindCountryById(
                                    int.Parse(DataSecurityTripleDES.GetPlainText(addressDTO.CountryId))));

                            if (countryDTO != null)
                            {
                                addressDTO.CountryName = countryDTO.Name;
                            }
                        }

                        IEnumerable <string> regionAliases = GetAllRegionAliases();

                        AddressViewModel addressViewModel = new AddressViewModel()
                        {
                            Id            = addressDTO.Id,
                            City          = addressDTO.City,
                            Line1         = addressDTO.Line1,
                            Line2         = addressDTO.Line2,
                            Postcode      = addressDTO.Postcode,
                            RegionAlias   = addressDTO.RegionAlias,
                            RegionAliases = GenUtil.GetSelectListItems(regionAliases)
                        };

                        return(View("EditAddress", addressViewModel));
                    }
                }
            }
            return(View("Error"));
        }