public bool IsValid(Session session) { Repo <Session> sessionRepo = new SessionRepo(); Session res = sessionRepo.Read(session); return(res.Id > 0); }
public DTO.Messages.Wrapper GetAll() { var Result = AuthorizeResponse(); if (Result.Messages.Count > 0) { Result.Code = 400; Result.Status = "Bad Request"; return(Result); } var Session = SessionRepo.GetOne(Token.jti); var Cart = new Dictionary <DTO.Projection.Recommendation, int>(); var Products = ProductRepo.QueryableCollection .Where(x => Session.Cart.ContainsKey(x.Id)) .Select(x => new DTO.Projection.Recommendation { Id = x.Id, Name = x.Name, Price = x.Price, Images = x.Images }); foreach (var Product in Products) { Session.Cart.TryGetValue(Product.Id, out int Quantity); Cart.Add(Product, Quantity); } Result.Data = Cart; return(Result); }
public void LoadUserTest() { var userRepo = new UserRepo(); var sessionRepo = new SessionRepo(); var balanceRepo = new BalanceLogRepo(); var user = new User(); userRepo.Save(user); Assert.IsNotNull(user.Id, "Not saved."); var session = new Session { UserId = user.Id }; sessionRepo.Save(session); var date = DateTime.UtcNow; balanceRepo.Save(new BalanceLog { UserId = user.Id, Amount = 3, Comment = "comment", Date = date }); var manager = new UserManager(); var loaded = manager.LoadBySessionKey(session.Id).WithBallanceLog(); Assert.IsNotNull(loaded, "Not loaded"); Assert.AreEqual(user.Id, loaded.Id, "Loaded incorrectly"); Assert.IsNotNull(loaded.BallanceLog, "Balance log is null."); Assert.AreEqual(1, loaded.BallanceLog.Count(), "Balance log count incorrect."); var balance = loaded.BallanceLog.First(); Assert.AreEqual(3, balance.Amount, "Amount incorrect."); Assert.AreEqual("comment", balance.Comment, "Comment incorrect."); Assert.AreEqual(date, balance.Date, "Date incorrect."); }
public bool Logout(Credential cr) { Repo <User> ur = new UserRepo(); ICollection <User> ulist = ur.ReadAll(); User user = null; foreach (var el in ulist) { if (el.Credential.Username == cr.Username && el.Credential.Password == cr.Password) { user = el; } } if (user == null) { return(false); } Repo <Session> sessionRepo = new SessionRepo(); ICollection <Session> sessions = sessionRepo.ReadAll(); Session session = null; foreach (var el in sessions) { if (el.Username == user.Credential.Username) { session = el; } } if (session == null) { return(false); } return(sessionRepo.Delete(session)); }
public SessionsRepoTest() { var dbOptions = DbInMemory.getDbInMemoryOptions(dbName); db = new TCSContext(dbOptions); sessionRepo = new SessionRepo(dbOptions); }
private void SessionViewDetail_Loaded(object sender, RoutedEventArgs e) { if (FormMode != FormModes.New) { SessionEntity = SessionRepo.FindByID(_sessionID); } }
private void popBtnAddButton_Click(object sender, RoutedEventArgs e) { if (FormMode == FormModes.View) { this.ActualParent.Close(); return; } SessionEntity.created_by = SessionEntity.updated_by = Utilities.UserSession.UserID; if (FormMode == FormModes.New) { SessionEntity.created_by = Utilities.UserSession.UserID; SessionRepo.Insert(SessionEntity); } else if (FormMode == FormModes.Edit) { SessionRepo.Update(SessionEntity); } var parent = (ucSessionListView)this.ParentContainer; parent.RefreshList(); this.ActualParent.Close(); }
public void CreateSession(string sID) { try { SessionRepo sessionRepo = new SessionRepo(); sessionRepo.CreateSession(sID); } catch (Exception ex) { LoggingHelper.WriteToFile("SessionManager/Errors/", "CreateSession_" + sID, ex.InnerException?.Message, ex.Message + " Sourse :" + ex.Source + " Stack Trace :" + ex.StackTrace); } }
public UnitOfWorkSessionTest() { var dbInMemory = DbInMemory.getDbInMemoryOptions(dbName); var personRepo = new PersonRepo(dbInMemory); var sessionRepo = new SessionRepo(dbInMemory); var reasonRepo = new ReasonRepo(dbInMemory); var classRepo = new ClassRepo(dbInMemory); var semesterRepo = new SemesterRepo(dbInMemory); db = new TCSContext(dbInMemory); unitSession = new UnitOfWorkSession(personRepo, reasonRepo, sessionRepo, classRepo, semesterRepo); }
public DTO.Messages.Wrapper RemoveOne(DTO.Messages.AddToCart ToBeRemoved = null) { var Result = AuthorizeResponse(); if (ToBeRemoved == null) { Result.Messages.Add("PostBody", "can't be empty"); } if (string.IsNullOrWhiteSpace(ToBeRemoved.ProductId)) { Result.Messages.Add("ProductId", "can't be empty"); } if (ToBeRemoved.Quantity == 0) { Result.Messages.Add("Quantity", "can't be Zero (0)"); } if (Result.Messages.Count > 0) { Result.Code = 400; Result.Status = "Bad Request"; return(Result); } var Session = SessionRepo.GetOne(Token.jti); var Removed = false; if (ToBeRemoved.Quantity < 0) { Session.Cart.Remove(ToBeRemoved.ProductId); Removed = true; } else { Session.Cart.TryGetValue(ToBeRemoved.ProductId, out int Left); if (Left < 1 || Left - ToBeRemoved.Quantity < 1) { Session.Cart.Remove(ToBeRemoved.ProductId); Removed = true; } else { Session.Cart[ToBeRemoved.ProductId] = (Left - ToBeRemoved.Quantity); Removed = false; } } SessionRepo.Save(Session); Result.Messages.Add("ItemStatus", Removed ? "Ok" : "Reduced"); Result.Data = ToBeRemoved; return(Result); }
public User LoadBySessionKey(string sessionKey) { var sessionRepo = new SessionRepo(); var session = sessionRepo.GetAll().FirstOrDefault(s => s.Id == sessionKey); var userRepo = new UserRepo(); var user = userRepo.GetAll().FirstOrDefault(u => u.Id == session.UserId); if (user != null) { if (user.Taxes == null) user.Taxes = new List<Tax>(); } return user; }
public bool ValidSession(SearchData SD) { try { SessionRepo sessionRepo = new SessionRepo(); return(sessionRepo.ChechSessionStatus(SD)); } catch (Exception ex) { LoggingHelper.WriteToFile("SessionManager/Errors/", "CreateSession_" + SD.sID, ex.InnerException?.Message, ex.Message + " Sourse :" + ex.Source + " Stack Trace :" + ex.StackTrace); return(false); } }
public DTO.Messages.Wrapper AddOne(DTO.Messages.AddToCart Adding = null) { var Result = AuthorizeResponse(); if (Adding == null) { Result.Messages.Add("PostBody", "can't be empty"); } else { if (string.IsNullOrWhiteSpace(Adding.ProductId)) { Result.Messages.Add("ProductId", "can't be empty"); } else { var Product = ProductRepo.GetOne(Adding.ProductId); if (Product == null) { Result.Messages.Add("ProductId", "is invalid"); } else if (Product.Scored() < 0) { Result.Messages.Add("Product", "is unavailable due to Promotions"); } } if (Adding.Quantity < 1) { Result.Messages.Add("Quantity", "must be greater than 0"); } } if (Result.Messages.Count > 0) { Result.Code = 400; Result.Status = "Bad Request"; return(Result); } var Session = SessionRepo.GetOne(Token.jti); Session.Cart.Add(Adding.ProductId, Adding.Quantity); SessionRepo.Save(Session); Result.Data = Adding; return(Result); }
public Session SignUp(Credential cr) { if (Exists(cr.Username)) { return(null); } Repo <User> userRepo = new UserRepo(); User user = new User(cr); userRepo.Create(user); Session session = new Session(user.Credential.Username, DateTime.MaxValue, LoginType.MAssenger, "A0-51-0B-BB-B8-3C"); Repo <Session> sessionRepo = new SessionRepo(); session = sessionRepo.Create(session); return(session); }
private void DeleteSessionRecord() { var win = getSelectedValue(); if (win == null || win.SessionID == 0) { Message(MessageTypes.Error, "Please Select to delete Session Detail"); return; } if (!DeleteMessage()) { return; } SessionRepo.Remove(win.SessionID); RefreshList(); }
ISession ISessionFacade.Create(string origin) { if (string.IsNullOrEmpty(origin)) { throw new ArgumentNullException("origin"); } Session newSession = new Session() { createDT = DateTimeOffset.UtcNow , expireDT = null , origin = origin , UID = Guid.NewGuid() }; SessionRepo.Insert(newSession); Dimension.SaveChanges(); return(newSession); }
public void GetSearchResult() { try { SearchReq searchInputData = PreparesSearchObj(); //map from general req to tbo req var TBOReq = SearchMapper.MapSearchReq(searchInputData); var searchResponse = SearchService.Search(TBOReq, searchData.sID); //save Provider session id in database SessionRepo manager = new SessionRepo(); manager.SaveSessions(5, searchResponse.SessionId, searchData.sID, searchData.SearchRooms); searchOutputs = searchResponse.HotelResultList.ToList(); } catch (Exception ex) { LoggingHelper.WriteToFile("TBOLogs/SearchController/Errors/", "TBOIntegrationManagement" + "INController" + searchData.sID, ex.InnerException?.Message, ex.Message + ex.StackTrace); throw ex; } }
public Session Login(Credential cr) { Repo <User> ur = new UserRepo(); ICollection <User> ulist = ur.ReadAll(); User user = null; foreach (var el in ulist) { if (el.Credential.Username == cr.Username && el.Credential.Password == cr.Password) { user = el; } } if (user == null) { return(null); } Session session = new Session(user.Credential.Username, DateTime.MaxValue, LoginType.MAssenger, "A0-51-0B-BB-B8-3C"); Repo <Session> sessionRepo = new SessionRepo(); session = sessionRepo.Create(session); return(session); }
public DTO.Messages.Wrapper AddPaymentAddress(DTO.Messages.TemporaryAddress address = null) { var Result = AuthorizeResponse(); if (address == null) { Result.Messages.Add("PostBody", "It mustn't be empty"); } if (string.IsNullOrWhiteSpace(address.Location)) { Result.Messages.Add("Location", "It mustn't be empty"); } if (string.IsNullOrWhiteSpace(address.Recipent)) { Result.Messages.Add("Recipent", "It mustn't be empty"); } if (string.IsNullOrWhiteSpace(address.Phone)) { Result.Messages.Add("Phone", "It mustn't be empty"); } if (Result.Messages.Count > 0) { Result.Code = 400; Result.Status = "Bad Request"; return(Result); } var Session = SessionRepo.GetOne(Token.jti); Session.DeliveryAddress = address; var Saved = SessionRepo.Save(Session); Result.Messages.Add("PaymentAddress", (Saved ? "Ok" : "Fail")); return(Result); }
public ScraperService(ScraperContext _ctx) { ctx = _ctx; resultRepo = new ScraperSingleResultRepo(ctx); sessionRepo = new SessionRepo(ctx); }
public bool Logout(Session session) { Repo <Session> sessionRepo = new SessionRepo(); return(sessionRepo.Delete(session)); }
public HotelSearchResponse GetSearchResult(SearchData searchData) { try { var tasks = new List <Task>(); var tokenSource1 = new CancellationTokenSource(); var tokenSource2 = new CancellationTokenSource(); List <HotelSearchResult> searchResults = new List <HotelSearchResult>(); HotelSearchResponse searchResponse = new HotelSearchResponse(); SessionManager sessionManager = new SessionManager(); // add validation if (!ValidateSearchData(searchData)) { searchResponse.Status = 1; // invalid data return(searchResponse); } // sure if session vaild ******** if (sessionManager.ValidSession(searchData)) { // get hotel data From DB SessionRepo sessionRepo = new SessionRepo(); var HotelSRes = sessionRepo.GetDataBySession(searchData); if (HotelSRes != null) { return(HotelSRes); } return(null); } //MG data not found in db new SID searchData = PrepareSearchData(searchData); if (searchData != null) { using (ProviderManager pm = new ProviderManager()) { pm.searchData = searchData; pm.GetHotelSearchResultForAllProviders(); // searchResults = pm.HotelSearchResults; // searchResults = GetLowestPrice(searchResults); searchResponse = pm.searchResponse; //searchResults = GetLowestPrice(searchResponse.HotelResult); searchResults = searchResponse.HotelResult; searchResponse.HotelResult = searchResults; searchResponse.Locations = searchResponse.HotelResult.GroupBy(x => x.Location).Select(x => x.FirstOrDefault()).Select(a => a.Location).ToList(); tasks.Add(Task.Factory.StartNew(() => { if (searchResults.Count > 0) { SaveSearchResult(searchResults, searchData.sID);///////////////// } }, tokenSource1.Token)); Task.WaitAll(tasks.ToArray()); } } return(searchResponse); } catch (HotelSearchInputException EX) { return(new HotelSearchResponse() { Status = 1, //"Invalid" ResultException = new ResultException() { Code = EX.Code, ExceptionMessage = EX.Message } }); } catch (Exception ex) { LoggingHelper.WriteToFile("SearchController/Errors/", "SearchController" + "INServOrch" + searchData.sID, ex.InnerException?.Message, ex.Message + ex.StackTrace); return(new HotelSearchResponse()); } }
public ScraperController(ScraperContext ctx) { Ctx = ctx; scraperService = new ScraperService(Ctx); sessionRepo = new SessionRepo(Ctx); }
public ActionResult Index(string Email, string Password, string OrganizationId, string returnUrl) { ViewBag.Message = ""; ViewBag.SuccessMessage = ""; if (Membership.ValidateUser(Email, Password)) // if (userrepo.ValidateUser(loginView.Email, loginView.Password)) { var user = (CustomMembershipUser)Membership.GetUser(Email, false); var userdetail = db.getPersonalDetail(user.UserId); if (user != null) { SessionVM userModel = new SessionVM() { UserId = user.UserId, FullName = user.FullName, Email = user.Email, //ActualRoleId = user.RoleId, RoleId = user.RoleId, IsAdmin = user.IsAdmin, //IsManager= confirmer.IsReportingManager(user.PersonalId); }; SessionRepo sesrepo = new SessionRepo(); var ses = sesrepo.GetSessionById(user.UserId); if (ses == null) { sesrepo.AddSession(new SC_LoginHistory() { UserId = user.UserId, LoginDate = DateTime.Now, RoleId = 0, OrganizationId = (int)userdetail.OrganizationId, //Convert.ToInt32(OrganizationId), ActualOrganizationId = (int)userdetail.OrganizationId, // Convert.ToInt32(OrganizationId), LogOutDate = DateTime.Now.AddMinutes(1200), }); } else { sesrepo.EditSession(new SC_LoginHistory() { UserId = user.UserId, LoginDate = DateTime.Now, RoleId = 0, OrganizationId = (int)userdetail.OrganizationId, //Convert.ToInt32(OrganizationId), ActualOrganizationId = (int)userdetail.OrganizationId, // Convert.ToInt32(OrganizationId), LogOutDate = DateTime.Now.AddMinutes(1200), LoginId = ses.LoginId }); } string userData = JsonConvert.SerializeObject(userModel); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket ( 1, user.Email, DateTime.Now, DateTime.Now.AddMinutes(1200), false, userData ); string enTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie("CookieUNITED1", enTicket); faCookie.Expires = DateTime.Now.AddMinutes(1200); Response.Cookies.Add(faCookie); } if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } else { if (Password == "password") { return(RedirectToAction("ChangePassword", "Profile")); } return(RedirectToAction("Index", "Dashboard")); //return RedirectToAction("Index", "Dashboard"); } } else { ViewBag.Message = "Specified User doesn't exists"; } return(View()); }
public DTO.Messages.Wrapper MakeOrder([FromBody] DTO.Messages.CheckOutCart Data = null) { var Result = AuthorizeResponse(); var Session = SessionRepo.GetOne(Token.jti); if (Data == null) { Data = new DTO.Messages.CheckOutCart(); } if (Session.Cart.Count == 0) { Result.Messages.Add("Cart", "is empty, please choose something before check out"); } if (Session.DeliveryAddress == null) { Result.Messages.Add("DeliveryAddress", "is not set"); } if (Session.PaymentAddress == null) { Result.Messages.Add("PaymentAddress", "is not set"); } if (Result.Messages.Count > 0) { Result.Status = "Bad Request"; Result.Code = 400; return(Result); } var Cart = new Dictionary <DTO.Projection.Recommendation, int>(); var Products = ProductRepo.QueryableCollection .Where(x => Session.Cart.ContainsKey(x.Id)) .Select(x => new DTO.Projection.Recommendation { Id = x.Id, Name = x.Name, Price = x.Price, Images = x.Images }); foreach (var Product in Products) { Session.Cart.TryGetValue(Product.Id, out int Quantity); Cart.Add(Product, Quantity); } var Order = new DTO.Databases.Order { Note = Data.Note, OrdererId = Token.sub, Delivery = Session.DeliveryAddress, Payment = Session.PaymentAddress, Ordered = Cart }; OrderRepo.Save(Order); Session.Cart = new Dictionary <string, int>(); SessionRepo.Save(Session); return(Result); }
public void RefreshList() { AllSessions = SessionRepo.GetAll(); // ResetDataPager(gvSessionListView, radDataPager); }