Пример #1
0
        public bool Create(string email, string password, string fullname, string description, DateTime?birthday = null, UserRole role = UserRole.User, UserSex sex = UserSex.Other)
        {
            using (var db = new MeetUpDbContext())
            {
                var mailExists = db.Users.Any(u => u.Email == email);

                if (mailExists)
                {
                    return(false);
                }

                var salt       = HelperFunctions.Get_SALT();
                var hashedPass = HelperFunctions.Get_HASH_SHA512(password, email, salt);

                var user = new User
                {
                    Email       = email,
                    Password    = hashedPass,
                    Salt        = salt,
                    FullName    = fullname,
                    Description = description,
                    Birthday    = birthday,
                    Sex         = sex,
                    Role        = role,
                    CreateTime  = DateTime.Today,
                    LastOnline  = DateTime.Today
                };

                db.Users.Add(user);
                db.SaveChanges();

                return(true);
            }
        }
 public int SaveChanges()
 {
     // There is another location where we could create / modify Tracking records instead of in UnitOfWork object
     // Then we could not expose ChangeTracker in IFullDataContext... tempting...
     // TODO: left as an exercise ;-)
     return(_context.SaveChanges());
 }
Пример #3
0
        public bool SaveUserImage(int userId, string imagePath, int imageSize, string extension)
        {
            using (var db = new MeetUpDbContext())
            {
                var user = db.Users
                           .Where(u => u.Id == userId)
                           .FirstOrDefault();

                if (user == null)
                {
                    return(false);
                }

                var image = new Image
                {
                    Path      = imagePath,
                    UserId    = userId,
                    Size      = imageSize,
                    Extension = extension
                };

                user.Images.Add(image);
                db.SaveChanges();

                return(true);
            }
        }
Пример #4
0
        public void SaveDailySuggestionLog(int userId)
        {
            var d = new DailySuggestionLogs
            {
                Date   = DateTime.Now,
                UserId = userId
            };

            this.db.DailySuggestionLogs.Add(d);
            db.SaveChanges();
        }
Пример #5
0
        public void DeleteImage(int id)
        {
            using (var db = new MeetUpDbContext())
            {
                var image = db.Images
                            .Where(u => u.Id == id)
                            .FirstOrDefault();

                image.Deleted = true;
                db.SaveChanges();
            }
        }
Пример #6
0
        public void UpdateCity(int id,
                               string name = null,
                               int?deleted = null)
        {
            using (var db = new MeetUpDbContext())
            {
                var dbCity = db.Cities
                             .Where(u => u.Id == id)
                             .FirstOrDefault();

                dbCity.Name    = name ?? dbCity.Name;
                dbCity.Deleted = deleted ?? dbCity.Deleted;

                db.SaveChanges();
            }
        }
Пример #7
0
        public void Populate()
        {
            using (var db = new MeetUpDbContext())
            {
                if (!db.Cities.Any())
                {
                    var city = new City
                    {
                        Name = "Sofia"
                    };

                    db.Cities.Add(city);
                    db.SaveChanges();
                }
            }
        }
Пример #8
0
        public void UpdateUser(int id,
                               string fullname    = null,
                               string description = null,
                               int?cityId         = null,
                               DateTime?birthday  = null,
                               string password    = null,
                               int?active         = null,
                               int?deleted        = null,
                               int?banned         = null,
                               UserRole?role      = null,
                               UserSex?sex        = null)
        {
            using (var db = new MeetUpDbContext())
            {
                var dbUser = db.Users
                             .Where(u => u.Id == id)
                             .FirstOrDefault();

                if (password != null)
                {
                    var salt       = dbUser.Salt;
                    var hashedPass = HelperFunctions.Get_HASH_SHA512(password, dbUser.Email, salt);

                    dbUser.Password = hashedPass;
                }

                dbUser.FullName    = fullname ?? dbUser.FullName;
                dbUser.Description = description ?? dbUser.Description;
                dbUser.CityId      = cityId ?? dbUser.CityId;
                dbUser.Birthday    = birthday ?? dbUser.Birthday;
                dbUser.Active      = active ?? dbUser.Active;
                dbUser.Deleted     = deleted ?? dbUser.Deleted;
                dbUser.Banned      = banned ?? dbUser.Banned;
                dbUser.Sex         = sex ?? dbUser.Sex;
                dbUser.Role        = role ?? dbUser.Role;

                db.SaveChanges();
            }
        }
Пример #9
0
        public bool Create(string name)
        {
            using (var db = new MeetUpDbContext())
            {
                var cityExists = db.Cities.Any(u => u.Name == name);

                if (cityExists)
                {
                    return(false);
                }

                var city = new City
                {
                    Name = name,
                };

                db.Cities.Add(city);
                db.SaveChanges();

                return(true);
            }
        }