public static bool ValidateToken(string phoneNumber, string token) { try { using (var dbCtx = new MSDbContext()) { var userToken = (from t in dbCtx.Tokens join u in dbCtx.Users on t.UserId equals u.Id where t.TokenStr == token && u.Tel == phoneNumber && t.IsActive select new { t, u }).FirstOrDefault(); if (userToken == null) { return(false); } var now = DateTime.Now; var diff = now - userToken.t.LastUsageTime; if (diff.Days > 30) { return(false); } userToken.t.LastUsageTime = now; dbCtx.SaveChanges(); return(true); } } catch (Exception e) { var ex = new SelectFromDataBaseException(ExceptionMessage.ValidatingToken, e); Logger.Log.Error(ex.Message, ex); throw ex; } }
public static ServiceProviderSpecificResp SelectServiceProviderById(int id) { try { using (var dbCtx = new MSDbContext()) { var server = (from s in dbCtx.Servers join c in dbCtx.Categories on s.CategoryId equals c.Id join sp in dbCtx.ServerPhotos on s.Id equals sp.ServerId into ssp from sp in ssp.DefaultIfEmpty() where s.IsActive && c.IsActive && s.Id == id && (sp.IsPrimary || sp == null) select new { s, c, sp.Photo }).FirstOrDefault(); if (server == null) { return(null); } var photos = (from p in dbCtx.ServerPhotos where p.ServerId == id select p).ToList(); List <string> photoBase64List = new List <string>(); foreach (var photo in photos) { string temp = Convert.ToBase64String(photo.Photo); photoBase64List.Add(temp); } ServiceProviderSpecificResp serviceProvider = new ServiceProviderSpecificResp() { Id = server.s.Id, Name = server.s.Name, Address = server.s.Address, CategoryName = server.c.Name, CategoryId = server.c.Id, Tel = server.s.Tel, PrimaryPhoto = server.Photo != null?Convert.ToBase64String(server.Photo) : null, PhotoList = photoBase64List }; return(serviceProvider); } } catch (Exception e) { var ex = new SelectFromDataBaseException(ExceptionMessage.SelectFromCategoriesServerIdException, e); Logger.Log.Error(ex.Message, ex); throw ex; } }
public static List <Category> SelectAllCategories() { try { using (var dbCtx = new MSDbContext()) { var categories = (from t in dbCtx.Categories select t).ToList(); return(categories); } } catch (Exception e) { var ex = new SelectFromDataBaseException(ExceptionMessage.SelectFromCategoriesException, e); Logger.Log.Error(ex.Message, ex); throw ex; } }
public static User SelectUserByTel(string tel) { try { using (var dbCtx = new MSDbContext()) { var user = (from u in dbCtx.Users where u.Tel == tel select u).FirstOrDefault(); return(user); } } catch (Exception e) { var ex = new SelectFromDataBaseException(ExceptionMessage.SelectFromUsersByTelException, e); Logger.Log.Error(ex.Message, ex); throw ex; } }
public static bool ExistActivationByUser(ActivationCodeReq activationCode) { try { using (var dbCtx = new MSDbContext()) { var userActiovation = (from a in dbCtx.Activations join u in dbCtx.Users on a.UserId equals u.Id where a.ActivationCode == activationCode.Code && u.Tel == activationCode.Tel && a.IsActive select new { a, u }).FirstOrDefault(); return(userActiovation != null); } } catch (Exception e) { var ex = new SelectFromDataBaseException(ExceptionMessage.ExistActivationByUser, e); Logger.Log.Error(ex.Message, ex); throw ex; } }
public static List <ServiceProviderGeneralInfoResp> SelectLikedServicesByPageIndex(string userMobileNumber, int pageIndex) { try { using (var dbCtx = new MSDbContext()) { List <ServiceProviderGeneralInfoResp> spList = new List <ServiceProviderGeneralInfoResp>(); var user = UserAccounts.SelectUserByTel(userMobileNumber); var servers = (from s in dbCtx.Servers join likes in dbCtx.ServiceProviderLike on s.Id equals likes.ServerId join c in dbCtx.Categories on s.CategoryId equals c.Id join sp in dbCtx.ServerPhotos on s.Id equals sp.ServerId into ssp from sp in ssp.DefaultIfEmpty() where s.IsActive && c.IsActive && likes.UserId == user.Id && (sp.IsPrimary || sp == null) orderby s.Id descending select new { s, c, sp.Photo }).Skip(ItemsPerPage * pageIndex).Take(ItemsPerPage).ToList(); foreach (var server in servers) { var temp = new ServiceProviderGeneralInfoResp() { Id = server.s.Id, Name = server.s.Name, CategoryId = server.c.Id, CategoryName = server.c.Name, PrimaryPhoto = server.Photo != null?Convert.ToBase64String(server.Photo) : null }; spList.Add(temp); } return(spList); } } catch (Exception e) { var ex = new SelectFromDataBaseException(ExceptionMessage.SelectFromCategoriesIdServersException, e); Logger.Log.Error(ex.Message, ex); throw ex; } }