// GET: CraveatsUser public ViewResult Index(string sortOrder, string currentFilter, string searchString, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; Common.UserTypeEnum userTypeEnumFromSession = SessionManager.GetContextSessionOwnerType(); int?sessionLoggedUserId = int.Parse(DataSecurityTripleDES.GetPlainText( SessionManager.GetContextSessionLoggedUserID())); var users = (userTypeEnumFromSession == Common.UserTypeEnum.CraveatsAdmin) ? from u in db.User where u.Id != sessionLoggedUserId select u : from u in db.User where u.Id == 0 select u; if (!String.IsNullOrEmpty(searchString)) { users = users.Where(s => ((s.FirstName ?? "") + " " + (s.Surname ?? "")).Contains(searchString) || s.EmailAddress.Contains(searchString)); } switch (sortOrder) { case "name_desc": users = users.OrderByDescending(s => ((s.FirstName ?? "") + " " + (s.Surname ?? ""))); break; case "Date": users = users.OrderBy(s => s.LastUpdated); break; case "date_desc": users = users.OrderByDescending(s => s.LastUpdated); break; default: // Name ascending users = users.OrderBy(s => ((s.FirstName ?? "") + " " + (s.Surname ?? ""))); break; } int pageSize = 25; int pageNumber = (page ?? 1); return(View(users.ToPagedList(pageNumber, pageSize))); }
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")); }
public ActionResult EditPost(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var RestaurantToUpdate = db.Restaurant.Find(int.Parse(DataSecurityTripleDES.GetPlainText(id))); if (TryUpdateModel(RestaurantToUpdate, "", new string[] { "LastName", "FirstMidName", "EnrollmentDate" })) { try { db.SaveChanges(); return(RedirectToAction("Index")); } 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(RestaurantToUpdate)); }
public static bool RegisterSessionActivity(int?userID = null, DateTime?loggedInAt = null, DateTime?loggedOffAt = null) { object xLock = new object(); lock (xLock) { AuthenticatedUserInfo authenticatedUserInfo = HttpContext.Current.Session["loggeduser"] as AuthenticatedUserInfo; if (EditSessionTracking(new SessionTracking() { SessionID = HttpContext.Current.Session.SessionID, IPAddress = (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? string.Empty).Trim() == string.Empty ? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]?.Trim() : HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]?.Trim(), UserId = userID.HasValue ? userID : authenticatedUserInfo != null ? (int?)int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId)) : null, LoggedInAt = loggedInAt, LoggedOutAt = loggedOffAt }) != null) { return(true); } ; return(false); } }
public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } loggedUserId = int.Parse(DataSecurityTripleDES.GetPlainText(model.UserId)); var result = await ceUserManager.ChangePasswordAsync(loggedUserId, model.OldPassword, model.NewPassword); if (result.Succeeded) { var userDTO = await ceUserManager.FindByIdAsync(loggedUserId); if (userDTO != null) { AuthenticatedUserInfo authenticatedUserInfo = new AuthenticatedUserInfo(userDTO); Session["loggeduser"] = authenticatedUserInfo; SessionManager.RegisterSessionActivity(userID: loggedUserId, loggedInAt: DateTime.Now); await ceUserManager.SignIn(username : authenticatedUserInfo.FullName, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess })); } AddErrors(result); return(View(model)); }
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 ManageController() { if (Session != null && Session.Contents != null && Session["loggeduser"] != null) { AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo; loggedUserId = int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId)); } }
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")); }
// GET: RestaurantMenu/Edit/5 public ActionResult Edit(string id, string ownerType = null, string ownerId = null) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RestaurantMenu restaurantMenu = db.RestaurantMenu.Find(int.Parse(DataSecurityTripleDES.GetPlainText(id))); if (restaurantMenu == null) { return(HttpNotFound()); } return(View(restaurantMenu)); }
public ActionResult EditAddress(AddressViewModel model, string returnUrl) { SessionManager.RegisterSessionActivity(); IEnumerable <string> regionAliases = GetAllRegionAliases(); model.RegionAliases = GenUtil.GetSelectListItems(regionAliases); if (ModelState.IsValid) { DataProvider dataProvider = new DataProvider(); DAL.Address address = dataProvider.FindAddressById( int.Parse(DataSecurityTripleDES.GetPlainText(model.Id))); if (address != null) { AddressDTO addressDTO = new AddressDTO() { Id = model.Id, City = model.City, Line1 = model.Line1, Line2 = model.Line2, Postcode = model.Postcode, RegionAlias = model.RegionAlias }; using (DAL.CraveatsDbContext c = new DAL.CraveatsDbContext()) { addressDTO.RegionId = DataSecurityTripleDES.GetEncryptedText( c.Region.FirstOrDefault(r => r.CountryISO2 == "CA" && r.RegionAlias == addressDTO.RegionAlias).Id); addressDTO.CountryId = DataSecurityTripleDES.GetEncryptedText( c.Country.FirstOrDefault(s => s.ISO2 == "CA").Id); address = c.Address.FirstOrDefault(u => u.Id == address.Id); address = EntityDTOHelper.MapToEntity <AddressDTO, DAL.Address>(addressDTO, address); c.SaveChanges(); return(RedirectToAction("ProfileView")); } } } // Something is not right - so render the registration page again, // keeping the data user has entered by supplying the model. return(View("EditAddress", model)); }
// GET: Restaurant/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Restaurant Restaurant = db.Restaurant.Find(int.Parse(DataSecurityTripleDES.GetPlainText(id))); if (Restaurant == null) { return(HttpNotFound()); } return(View(Restaurant)); }
public ActionResult Delete(string id) { try { Restaurant Restaurant = db.Restaurant.Find(int.Parse(DataSecurityTripleDES.GetPlainText(id))); db.Restaurant.Remove(Restaurant); db.SaveChanges(); } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. return(RedirectToAction("Delete", new { id = id, saveChangesError = true })); } return(RedirectToAction("Index")); }
// GET: RestaurantMenu/Delete/5 public ActionResult Delete(string id, bool?saveChangesError = false, string ownerType = null, string ownerId = null) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (saveChangesError.GetValueOrDefault()) { ViewBag.ErrorMessage = "Delete failed. Try again, and if the problem persists see your system administrator."; } var RestaurantMenuToUpdate = db.RestaurantMenu.Find(int.Parse(DataSecurityTripleDES.GetPlainText(id))); if (RestaurantMenuToUpdate == null) { return(HttpNotFound()); } return(View(RestaurantMenuToUpdate)); }
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 EditPost([Bind(Include = "Name, Brief, Detail, UnitPrice")] RestaurantMenu restaurantMenu, string id = null, string ownerId = null, string ownerType = null) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (restaurantMenu == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if ((restaurantMenu.Brief ?? string.Empty) == string.Empty || (restaurantMenu.Name ?? string.Empty) == string.Empty || (restaurantMenu.Detail ?? string.Empty) == string.Empty || (restaurantMenu.UnitPrice ?? 0) <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var RestaurantMenuToUpdate = db.RestaurantMenu.Find(int.Parse(DataSecurityTripleDES.GetPlainText(id))); try { RestaurantMenuToUpdate.UnitPrice = restaurantMenu.UnitPrice; RestaurantMenuToUpdate.Name = restaurantMenu.Name; RestaurantMenuToUpdate.Detail = restaurantMenu.Detail; RestaurantMenuToUpdate.Brief = restaurantMenu.Brief; 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(RestaurantMenuToUpdate)); }
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 Delete(string id, string ownerType = null, string ownerId = null) { try { RestaurantMenu restaurantMenu = db.RestaurantMenu.Find(int.Parse(DataSecurityTripleDES.GetPlainText(id))); db.RestaurantMenu.Remove(restaurantMenu); db.SaveChanges(); } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. return(RedirectToAction("Delete", new { id = DataSecurityTripleDES.GetEncryptedText(id), saveChangesError = true, ownerType = ownerType, ownerId = ownerId })); } return(RedirectToAction("Index", new { ownerType = ownerType, ownerId = ownerId })); }
// 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)); }
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 void Index() { string org1 = "1", org2 = "one", org3 = "this is some data"; byte[] key = null, iv = null; Assert.AreEqual(org1, DataSecurityTripleDES.GetPlainText( DataSecurityTripleDES.GetEncryptedText(org1 /*, out key, out iv*/) /*, key, iv*/)); Assert.AreEqual(org2, DataSecurityTripleDES.GetPlainText( DataSecurityTripleDES.GetEncryptedText(org2 /*, out key, out iv*/) /*, key, iv*/)); Assert.AreEqual(org3, DataSecurityTripleDES.GetPlainText( DataSecurityTripleDES.GetEncryptedText(org3 /*, out key, out iv*/) /*, key, iv*/)); // Arrange HomeController controller = new HomeController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public static string GetContextSessionID() { object xLock = new object(); int? UserId = (int?)int.Parse(DataSecurityTripleDES.GetPlainText(GetContextSessionLoggedUserID())); lock (xLock) { string SessionID = HttpContext.Current.Session.SessionID, IPAddress = (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? string.Empty).Trim() == string.Empty ? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]?.Trim() : HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]?.Trim(); SessionTracking result = null; using (CraveatsDbContext craveatsDbContext = new CraveatsDbContext()) { result = craveatsDbContext.SessionTracking.FirstOrDefault(u => u.IPAddress == IPAddress && u.SessionID == SessionID && u.UserId == UserId); } return(DataSecurityTripleDES.GetEncryptedText(result?.Id ?? 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)); }
// GET: RestaurantMenu public ViewResult Index( string ownerType, string ownerId, string sortOrder, string currentFilter, string searchString, int?page) { if (ownerType != null && ownerId != null) { ViewBag.ownerType = ownerType; ViewBag.ownerId = ownerId; } else { ownerType = DataSecurityTripleDES.GetEncryptedText((int)SessionManager.GetContextSessionOwnerType()); ownerId = SessionManager.GetContextSessionLoggedUserID(); ViewBag.ownerType = ownerType; ViewBag.ownerId = ownerId; } ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; int?filterId = int.Parse(DataSecurityTripleDES.GetPlainText(ownerId)); var RestaurantMenus = SessionManager.GetContextSessionOwnerType() == UserTypeEnum.PartnerRestaurant ? from s in db.RestaurantMenu where s.OwnerId == filterId && s.OwnerType == 2 && s.ServiceStatus == 1 select s : from s in db.RestaurantMenu select s; if (!String.IsNullOrEmpty(searchString)) { RestaurantMenus = RestaurantMenus.Where(s => s.Name.Contains(searchString) || s.Detail.Contains(searchString)); } switch (sortOrder) { case "name_desc": RestaurantMenus = RestaurantMenus.OrderByDescending(s => s.Name); break; case "Date": RestaurantMenus = RestaurantMenus.OrderBy(s => s.LastUpdated); break; case "date_desc": RestaurantMenus = RestaurantMenus.OrderByDescending(s => s.LastUpdated); break; default: // Name ascending RestaurantMenus = RestaurantMenus.OrderBy(s => s.Name); break; } int pageSize = 25; int pageNumber = (page ?? 1); return(View(RestaurantMenus.ToPagedList(pageNumber, pageSize))); }
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")); }
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 AddAddress(AddressViewModel model, string returnUrl) { SessionManager.RegisterSessionActivity(); IEnumerable <string> regionAliases = GetAllRegionAliases(); model.RegionAliases = GenUtil.GetSelectListItems(regionAliases); if (ModelState.IsValid) { AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo; if (authenticatedUserInfo != null) { int ownerType = model.OwnerType?.Length > 0 ? int.Parse(DataSecurityTripleDES.GetPlainText(model.OwnerType)) : -1; int ownerId = model.OwnerId?.Length > 0 ? int.Parse(DataSecurityTripleDES.GetPlainText(model.OwnerType)) : -1; DAL.User addressOwner = null; if (!(ownerType > -1 && ownerId > 0)) { addressOwner = new CEUserManager().FindById( int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId))); } DataProvider dataProvider = new DataProvider(); AddressDTO addressDTO = new AddressDTO() { City = model.City, Line1 = model.Line1, Line2 = model.Line2, Postcode = model.Postcode, RegionAlias = model.RegionAlias }; if (addressOwner != null && !addressOwner.AddressId.HasValue) { addressDTO.OwnerType = (int)Common.OwnerTypeEnum.User; addressDTO.OwnerId = authenticatedUserInfo.UserId; using (DAL.CraveatsDbContext c = new DAL.CraveatsDbContext()) { addressDTO.RegionId = DataSecurityTripleDES.GetEncryptedText( c.Region.FirstOrDefault(r => r.CountryISO2 == "CA" && r.RegionAlias == addressDTO.RegionAlias).Id); addressDTO.CountryId = DataSecurityTripleDES.GetEncryptedText( c.Country.FirstOrDefault(s => s.ISO2 == "CA").Id); DAL.Address newAddress = EntityDTOHelper.MapToEntity <AddressDTO, DAL.Address>( addressDTO, null, true); newAddress.AddressStatus = (int?)Common.AddressStatusEnum.Active; c.Entry(newAddress).State = System.Data.Entity.EntityState.Added; c.SaveChanges(); addressOwner = c.User.FirstOrDefault(u => u.Id == newAddress.OwnerId.Value); addressOwner.AddressId = newAddress.Id; addressOwner.LastUpdated = DateTime.Now; c.SaveChanges(); return(RedirectToAction("ProfileView", "Profile")); } } else if (ownerType > -1 && ownerId > 0) { addressDTO.OwnerType = ownerType; addressDTO.OwnerId = model.OwnerId; using (DAL.CraveatsDbContext c = new DAL.CraveatsDbContext()) { addressDTO.RegionId = DataSecurityTripleDES.GetEncryptedText( c.Region.FirstOrDefault(r => r.CountryISO2 == "CA" && r.RegionAlias == addressDTO.RegionAlias).Id); addressDTO.CountryId = DataSecurityTripleDES.GetEncryptedText( c.Country.FirstOrDefault(s => s.ISO2 == "CA").Id); DAL.Address newAddress = EntityDTOHelper.MapToEntity <AddressDTO, DAL.Address>( addressDTO, null, true); newAddress.AddressStatus = (int?)Common.AddressStatusEnum.Active; c.Entry(newAddress).State = System.Data.Entity.EntityState.Added; c.SaveChanges(); DAL.Restaurant restaurant = c.Restaurant.FirstOrDefault(u => u.Id == newAddress.OwnerId.Value); restaurant.AddressId = newAddress.Id; restaurant.LastUpdated = DateTime.Now; c.SaveChanges(); return(RedirectToAction("Index", "RestaurantMenu", new { ownerType = DataSecurityTripleDES.GetEncryptedText((int)Common.OwnerTypeEnum.ServiceProvider), ownerId = DataSecurityTripleDES.GetEncryptedText(restaurant.Id) })); } } ModelState.AddModelError("", "An address exists for this owner."); } } // Something is not right - so render the registration page again, // keeping the data user has entered by supplying the model. return(View(model)); }
internal static T2 MapToEntity <T1, T2>(T1 sourceDTO, T2 targetEntity, bool createInstance = false) { try { if (sourceDTO != null) { if (targetEntity == null && createInstance) { targetEntity = Activator.CreateInstance <T2>(); } PropertyInfo[] sourceProps = sourceDTO.GetType().GetProperties(), targetProps = targetEntity?.GetType().GetProperties(); if (targetProps?.Length > 0) { foreach (PropertyInfo propertyInfo in targetProps) { if (propertyInfo.CanWrite) { PropertyInfo uProp = sourceProps.FirstOrDefault(u => u.Name == propertyInfo.Name && u.CanRead); if (uProp != null) { if (!(propertyInfo.Name.ToLower().EndsWith("id") && ((propertyInfo.PropertyType == typeof(System.Int32)) || ((propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) && Nullable.GetUnderlyingType(propertyInfo.PropertyType) == typeof(System.Int32))))) { object objValue = uProp.GetValue( sourceDTO, null); if (objValue != null) { if (propertyInfo.PropertyType == uProp.PropertyType) { propertyInfo.SetValue( targetEntity, objValue); } else { if (propertyInfo.Name == "OwnerType" && (propertyInfo.ReflectedType.FullName == "WebApplication.DAL.Address" || propertyInfo.ReflectedType.FullName == "WebApplication.Models.ViewModel.AddressDTO")) { int?iVal = int.Parse(DataSecurityTripleDES.GetPlainText( uProp.GetValue( sourceDTO, null))); propertyInfo.SetValue( targetEntity, iVal); } else { propertyInfo.SetValue(targetEntity, Convert.ChangeType( objValue, propertyInfo.PropertyType)); } } } } else { object objValue = DataSecurityTripleDES.GetPlainText( uProp.GetValue( sourceDTO, null)); if (objValue != null) { if (((propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) && Nullable.GetUnderlyingType(propertyInfo.PropertyType) == typeof(System.Int32))) { propertyInfo.SetValue(targetEntity, (int?)int.Parse(objValue.ToString())); } else { propertyInfo.SetValue(targetEntity, Convert.ChangeType(objValue, propertyInfo.PropertyType)); } } } } } } return(targetEntity); } } return(default(T2)); } catch (Exception e) { throw e; } }
// GET: Restaurant public ViewResult Index(string sortOrder, string currentFilter, string searchString, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; Common.UserTypeEnum userTypeEnumFromSession = SessionManager.GetContextSessionOwnerType(); int?sessionLoggedUserId = int.Parse(DataSecurityTripleDES.GetPlainText( SessionManager.GetContextSessionLoggedUserID())); var Restaurants = (userTypeEnumFromSession == Common.UserTypeEnum.CraveatsAdmin) ? from s in db.Restaurant select s : (userTypeEnumFromSession == Common.UserTypeEnum.PartnerRestaurant) ? from s in db.Restaurant where s.PartnerUserId == sessionLoggedUserId select s : from s in db.Restaurant where s.PartnerUserId == 0 select s; if (!String.IsNullOrEmpty(searchString)) { Restaurants = Restaurants.Where(s => s.Name.Contains(searchString) || s.Detail.Contains(searchString)); } switch (sortOrder) { case "name_desc": Restaurants = Restaurants.OrderByDescending(s => s.Name); break; case "Date": Restaurants = Restaurants.OrderBy(s => s.LastUpdated); break; case "date_desc": Restaurants = Restaurants.OrderByDescending(s => s.LastUpdated); break; default: // Name ascending Restaurants = Restaurants.OrderBy(s => s.Name); break; } int pageSize = 25; int pageNumber = (page ?? 1); return(View(Restaurants.ToPagedList(pageNumber, pageSize))); }
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")); }
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()); }