public InvitacionPedidoService(MasterEntities db) { this.db = db; InvitacionPedidoRepo = new InvitacionPedidoRepository(db); UsuarioSvc = new UsuarioService(db); EmailSvc = new EmailService(); }
/// <summary> /// Authenticate user by validating his password. /// </summary> /// <param name="login">User unique login name.</param> /// <param name="password">User password.</param> /// <returns><c>true</c> if provided credentials exist in the master database.</returns> internal bool Authenticate(string login, string password) { if (string.IsNullOrWhiteSpace(login)) { throw new ArgumentException("Login must not be empty."); } if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentException("Password must not be empty."); } var masterConnection = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnection)) { var hash = password.Hash(); var user = mc.Users.Where(u => u.Login == login.Trim() && u.Password == hash) .Select(u => u) .SingleOrDefault(); if (user != null) { //TODO: consider do NOT write in master database every user operation; // for example, try to write in the user personal database instead. user.LastAccess = DateTime.UtcNow; mc.SaveChanges(); return(true); } } return(false); }
/// <summary> /// Delete specific user from master database records by his internal unique ID. /// Note: user personal database file will NOT be deleted since this is manual operation. /// </summary> /// <param name="userId">User ID to delete.</param> public void DeleteUser(Guid userId) { LogManager.GetCurrentClassLogger().LogClientIP("DisableUser"); if (userId == Guid.Empty) { throw new ArgumentException("userId"); } var masterConnectioString = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnectioString)) { var user = ModelHelper.GetUserById(mc, userId); mc.Users.DeleteObject(user); mc.SaveChanges(); var absolutePath = DatabaseManager.ResolveDataDirectory(user.DatabasePath); var userFolder = new FileInfo(absolutePath).Directory; if (userFolder != null) { var deletedFolderName = "DELETED_" + userFolder.Name; var parentUserFolder = userFolder.Parent; if (parentUserFolder != null) { var targetFolder = new DirectoryInfo(Path.Combine(parentUserFolder.FullName, deletedFolderName)); Directory.Move(userFolder.FullName, targetFolder.FullName); } } } }
public InvitacionPedidoService() { db = new MasterEntities(); InvitacionPedidoRepo = new InvitacionPedidoRepository(db); UsuarioSvc = new UsuarioService(db); EmailSvc = new EmailService(); }
public JsonResult SaveOrder(OrderVM O) { bool status = false; if (ModelState.IsValid) { using (MasterEntities dc = new MasterEntities()) { Order order = new Order { OrderNo = O.OrderNo, OrderDate = O.OrderDate, Description = O.Description }; foreach (var i in O.OrderDetails) { // // i.TotalAmount = order.OrderDetails.Add(i); } dc.Orders.Add(order); dc.SaveChanges(); status = true; } } else { status = false; } return(new JsonResult { Data = new { status = status } }); }
public PedidoService(MasterEntities db) { Db = db; PedidoRepo = new PedidoRepository(Db); Loginsvc = new LoginService(Db); UsuarioSvc = new UsuarioService(Db); InvitacionPedidoSvc = new InvitacionPedidoService(Db); InvitacionPedidoGustoEmpanadaUsuarioSvc = new InvitacionPedidoGustoEmpanadaUsuarioService(Db); GustoEmpanadaSvc = new GustoEmpanadaService(Db); }
public void Init(HttpApplication context) { MasterEntities entitiesCtx = new MasterEntities(); IEntityRepository <Tenant, Guid> tenantRepository = new EntityRepository <Tenant, Guid>(entitiesCtx); try { ValidateRequest(new HttpContextWrapper(context.Context), tenantRepository); } catch (HttpException) // will throw at the app start-up { } }
/// <summary> /// Gets connection string to the user personal database based on user ID. /// </summary> /// <param name="userId">Unique user ID.</param> /// <returns>Connection string to the user personal database.</returns> private string GetPersonalConnection(Guid userId) { if (userId == Guid.Empty) { throw new ArgumentException("userId"); } var masterConnection = dbManager.GetMasterConnection(DefaultFolder); User user; using (var mc = new MasterEntities(masterConnection)) { user = mc.Users.Single(u => u.Id == userId); } return(dbManager.GetPersonalConnection(user.DatabasePath)); }
protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { HttpContextBase httpContext = request.Properties["MS_HttpContext"] as HttpContextBase; MasterEntities entitiesCtx = new MasterEntities(); IEntityRepository <Tenant, Guid> tenantRepository = new EntityRepository <Tenant, Guid>(entitiesCtx); ValidateRequest(httpContext, tenantRepository); var tenant = httpContext.Items["App:Tenant"] as string; if (tenant == null) { return(Task.FromResult(request.CreateResponse(HttpStatusCode.NotFound))); } return(base.SendAsync(request, cancellationToken)); }
/// <summary> /// Gets connection string to the user personal database based on user ID. /// </summary> /// <param name="login">User login.</param> /// <returns>Connection string to the user personal database.</returns> public string GetPersonalConnection(string login) { if (string.IsNullOrEmpty(login)) { throw new ArgumentException("login"); } var masterConnection = dbManager.GetMasterConnection(DefaultFolder); User user; using (var mc = new MasterEntities(masterConnection)) { user = mc.Users.Single(u => u.Login == login); } return(dbManager.GetPersonalConnection(user.DatabasePath)); }
/// <summary> /// Verify user personal database file integrity by comparing checksums. /// </summary> /// <param name="userId">Unique user ID.</param> /// <returns>True if the checksums match and there is no database corruption; otherwise, false.</returns> public bool VerifyUserDatabase(Guid userId) { LogManager.GetCurrentClassLogger().LogClientIP("VerifyUserDatabase"); if (userId == Guid.Empty) { throw new ArgumentException("userId"); } var masterConnection = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnection)) { var user = ModelHelper.GetUserById(mc, userId); var absolutePath = DatabaseManager.ResolveDataDirectory(user.DatabasePath); return(dbManager.VerifyDatabase(absolutePath)); } }
/// <summary> /// Change user password or email to new values. /// </summary> /// <param name="oldPassword">User old password.</param> /// <param name="newPassword">User new password.</param> /// <param name="newEmail">User new email.</param> public void Update(string oldPassword, string newPassword, string newEmail) { if (string.IsNullOrWhiteSpace(oldPassword)) { throw new ArgumentException("Old password must not be empty."); } if (string.IsNullOrWhiteSpace(newPassword)) { throw new ArgumentException("New password must not be empty."); } // Check password min length if (newPassword.Length < 5) { throw new Exception("New password is too short. Minimum length is 5."); } // Check password max length if (newPassword.Length > 256) { throw new Exception("New password is too long. Maximum length is 256."); } var masterConnection = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnection)) { User user = ModelHelper.GetUserByLogin(mc, UserName); if (user.Password != oldPassword.Hash()) { throw new Exception("Old password is incorrect."); } user.Password = newPassword.Hash(); user.Email = string.IsNullOrWhiteSpace(newEmail) ? null : newEmail.Trim(); mc.SaveChanges(); } }
/// <summary> /// Get user info based on authenticated username. /// </summary> /// <returns>User info.</returns> public UserDTO GetUser() { var masterConnection = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnection)) { var usersMapper = ObjectMapperManager.DefaultInstance.GetMapper <User, UserDTO>(); var user = mc.Users.Where(u => u.Login == UserName) .Select(u => u) .Single(); //TODO: consider do NOT write in master database on user "login" action; // for example, try to write in the user personal database instead. user.LastAccess = DateTime.UtcNow; mc.SaveChanges(); return(usersMapper.Map(user)); } }
/// <summary> /// Check user login name for uniqueness. /// </summary> /// <param name="login">User login.</param> /// <returns><c>true</c> if user login name is unique.</returns> public bool IsLoginAvailable(string login) { if (string.IsNullOrWhiteSpace(login)) { throw new ArgumentException("Login must not be empty."); } // Remove leading and closing spaces (user typo) string newLogin = login.Trim(); // Check login min & max length if (newLogin.Length < 5 || newLogin.Length > 50) { return(false); } var masterConnection = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnection)) { return(ModelHelper.IsLoginAvailable(mc, newLogin)); } }
/// <summary> /// Update specific user data. /// </summary> /// <param name="userDto">User to update.</param> /// <returns>Last updated date.</returns> public DateTime UpdateUser(AdminUserDTO userDto) { LogManager.GetCurrentClassLogger().LogClientIP("UpdateUser"); if (userDto == null) { throw new ArgumentNullException("userDto"); } var masterConnection = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnection)) { User user = ModelHelper.GetUserById(mc, userDto.Id); user.Login = userDto.Login; if (!string.IsNullOrEmpty(userDto.Password)) { user.Password = userDto.Password.Hash(); } user.Email = string.IsNullOrWhiteSpace(userDto.Email) ? null : userDto.Email.Trim(); user.DatabasePath = userDto.DatabasePath; user.ServiceUrl = userDto.ServiceUrl; user.IsDisabled = userDto.IsDisabled; user.DisabledChanged = DateTime.UtcNow; mc.SaveChanges(); // After this method call "user.DisabledChanged" will be always initialized return(user.DisabledChanged.Value); } }
public PedidoRepository(MasterEntities db) { Db = db; }
public InvitacionPedidoGustoEmpanadaUsuarioRepository(MasterEntities db) { Db = db; }
public GustoEmpanadaService(MasterEntities db) { this.db = db; this.GustoEmpanadaRepository = new GustoEmpanadaRepository(db); }
public GustoEmpanadaService() { this.db = new MasterEntities(); this.GustoEmpanadaRepository = new GustoEmpanadaRepository(db); }
public UsuarioRepository(MasterEntities db) { Db = db; }
public GustoEmpanadaRepository(MasterEntities db) { Db = db; }
public InvitacionPedidoGustoEmpanadaUsuarioService(MasterEntities db) { this.db = db; InvitacionPedidoGustoEmpanadaUsuarioRepo = new InvitacionPedidoGustoEmpanadaUsuarioRepository(this.db); UsuarioSvc = new UsuarioService(db); }
/// <summary> /// Return filtered list of registered users from the system. /// </summary> /// <param name="queryFilter">Filter conditions.</param> /// <returns>List of users.</returns> public IList <AdminUserDTO> GetUsers(IQueryFilter queryFilter) { LogManager.GetCurrentClassLogger().LogClientIP("GetUsers"); if (queryFilter == null) { throw new ArgumentNullException("queryFilter"); } var records = new List <AdminUserDTO>(); var masterConnectioString = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnectioString)) { //TODO: remove duplicated code with GetJournalsCounts() method var query = from u in mc.Users select u; if (queryFilter is TextSearchFilter) { var textSearchFilter = queryFilter as TextSearchFilter; if (!string.IsNullOrEmpty(textSearchFilter.Contains)) { query = from user in query where user.Login.Contains(textSearchFilter.Contains) || user.Email.Contains(textSearchFilter.Contains) || user.DatabasePath.Contains(textSearchFilter.Contains) || user.ServiceUrl.Contains(textSearchFilter.Contains) select user; } } if (queryFilter.NotOlderThen.HasValue) { query = from user in query where user.LastAccess >= queryFilter.NotOlderThen.Value select user; } if (queryFilter.Upto.HasValue) { query = from user in query where user.LastAccess < queryFilter.Upto.Value select user; } query = query.OrderBy(user => user.Registered); if (queryFilter.Skip.HasValue) { query = query.Skip(queryFilter.Skip.Value); } if (queryFilter.Take.HasValue) { query = query.Take(queryFilter.Take.Value); } // End of duplicated code var res = query.ToList(); // No users take place yet, so nothing to return if (res.Count == 0) { return(records); } var userMaper = ObjectMapperManager.DefaultInstance.GetMapper <User, AdminUserDTO>(); records = res.Select(userMaper.Map) .Select(dto => { // Do not return password hash to client // by security considerations dto.Password = null; return(dto); }) .ToList(); } var drivesCache = new Dictionary <string, bool>(); foreach (var adminUser in records) { var resolvedFile = DatabaseManager.ResolveDataDirectory(adminUser.DatabasePath); if (File.Exists(resolvedFile)) { var file = new FileInfo(resolvedFile); adminUser.DatabaseSize = file.Length; // C:\ or D:\ etc. var driveName = Path.GetPathRoot(file.FullName); if (!string.IsNullOrEmpty(driveName)) { if (!drivesCache.ContainsKey(driveName)) { try { // Check drive free space info availability if (new DriveInfo(driveName).AvailableFreeSpace > 0) { drivesCache[driveName] = true; } } catch (UnauthorizedAccessException) { LogManager.GetCurrentClassLogger().Error("DriveInfo.AvailableFreeSpace for " + driveName + " is denied."); drivesCache[driveName] = false; } } if (drivesCache[driveName]) { // Free space available for IIS AppPool user account, not the entire disk long freeSpace = new DriveInfo(driveName).AvailableFreeSpace; adminUser.FreeDiskSpaceAvailable = freeSpace; } } } } return(records); }
public InvitacionPedidoRepository(MasterEntities db) { Db = db; }
public MasterEntities InitMaster() { return(masterContext ?? (masterContext = new MasterEntities())); }
/// <summary> /// Register new user with unique login name and password. /// </summary> /// <param name="login">User login name.</param> /// <param name="password">User password.</param> /// <returns>Created user object.</returns> public UserDTO Register(string login, string password) { if (string.IsNullOrWhiteSpace(login)) { throw new ArgumentException("Username must not be empty."); } if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentException("Password must not be empty."); } // Remove leading and closing spaces (user typo) string newLogin = login.Trim(); // Check login min length if (newLogin.Length < 5) { throw new Exception("Username is too short. Minimum length is 5."); } // Check login max length if (newLogin.Length > 50) { throw new Exception("Username is too long. Maximum length is 50."); } // Check password min length if (password.Length < 5) { throw new Exception("New password is too short. Minimum length is 5."); } // Check password max length if (password.Length > 255) { throw new Exception("New password is too long. Maximum length is 255."); } if (Properties.Settings.Default.Registration_Disabled) { var log = LogManager.GetCurrentClassLogger(); log.Warn("Registration failed. Attempt to use username: "******"ERR-REGS-0", ErrorMessage = "Registration failed.", Description = "Sorry, the subscription is temporarily suspended." }; throw new FaultException <FaultDetail>( faultDetail, new FaultReason(faultDetail.Description), new FaultCode("Receiver")); } var masterConnection = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnection)) { var usersMapper = ObjectMapperManager.DefaultInstance.GetMapper <User, UserDTO>(); // Check login uniqueness if (!ModelHelper.IsLoginAvailable(mc, newLogin)) { var faultDetail = new FaultDetail { ErrorCode = "ERR-REGS-1", ErrorMessage = "Registration failed.", Description = string.Format("Sorry, but username \"{0}\" is already in use. Please, try to pick another username.", newLogin) }; throw new FaultException <FaultDetail>( faultDetail, new FaultReason(faultDetail.Description), new FaultCode("Receiver")); } var user = new User { Id = Guid.NewGuid(), Login = newLogin, Password = password.Hash(), Registered = DateTime.UtcNow, IsDisabled = false, ServiceUrl = string.Empty // default service for all users (for now) }; // Create personal database for user and save path to it // TODO: use custom password here to encrypt database with user.DatabasePath = dbManager.CreatePersonalDatabase(user.Id, user.Registered, DefaultFolder /*, password*/); mc.Users.AddObject(user); mc.SaveChanges(); // Creating default $ account var moneyService = new MoneyService { UserName = user.Login }; moneyService.CreateAccount("Cash", 2); return(usersMapper.Map(user)); } }
public UsuarioService() { db = new MasterEntities(); UsuarioRepo = new UsuarioRepository(db); }
public UsuarioService(MasterEntities db) { this.db = db; UsuarioRepo = new UsuarioRepository(this.db); }
public LoginService(MasterEntities db) { this.db = db; this.UsuarioRepo = new UsuarioRepository(db); }
/// <summary> /// Return count of users based on search filter. /// </summary> /// <param name="queryFilter">Filter conditions.</param> /// <returns>Count of filtered users.</returns> public int GetUsersCount(IQueryFilter queryFilter) { LogManager.GetCurrentClassLogger().LogClientIP("GetUsersCount"); if (queryFilter == null) { throw new ArgumentNullException("queryFilter"); } int count; var masterConnectioString = dbManager.GetMasterConnection(DefaultFolder); using (var mc = new MasterEntities(masterConnectioString)) { var query = from u in mc.Users select u; if (queryFilter is TextSearchFilter) { var textSearchFilter = queryFilter as TextSearchFilter; if (!string.IsNullOrEmpty(textSearchFilter.Contains)) { query = from user in query where user.Login.Contains(textSearchFilter.Contains) || user.Email.Contains(textSearchFilter.Contains) || user.DatabasePath.Contains(textSearchFilter.Contains) || user.ServiceUrl.Contains(textSearchFilter.Contains) select user; } } if (queryFilter.NotOlderThen.HasValue) { query = from user in query where user.LastAccess >= queryFilter.NotOlderThen.Value select user; } if (queryFilter.Upto.HasValue) { query = from user in query where user.LastAccess < queryFilter.Upto.Value select user; } query = query.OrderBy(user => user.Registered); if (queryFilter.Skip.HasValue) { query = query.Skip(queryFilter.Skip.Value); } if (queryFilter.Take.HasValue) { query = query.Take(queryFilter.Take.Value); } count = query.Count(); } return(count); }