private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.Title = "Home - Feed";
            DisableButtons();
            var _user = await Api.GetCurrentUserAsync();

            if (_user.Succeeded)
            {
                this.CurrentUser = _user.Value;

                using (var context = new InstaContext())
                {
                    if (!context.Users.Any(u => u.PK == this.CurrentUser.Pk))
                    {
                        var user = new UserModel
                        {
                            PK        = this.CurrentUser.Pk,
                            LastLogin = DateTime.Now
                        };

                        context.Users.Add(user);
                        context.SaveChanges();
                    }

                    this.UserModel           = context.Users.Include("Schedules").Include("Searches").Include("Tasks").First(u => this.CurrentUser.Pk == u.PK);
                    this.UserModel.LastLogin = DateTime.Now;
                    context.SaveChanges();
                }

                try
                {
                    TaskWorker.StartBackgroundWorker(this.UserModel.Id, this.Api);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("TaskWorker.StartBackgroundWorker" + Environment.NewLine + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                EnableButtons();

                profileImage.Fill      = new ImageBrush(new BitmapImage(new Uri(this.CurrentUser.ProfilePicture)));
                lblUsername.Content    = this.CurrentUser.UserName;
                progressBar.Visibility = Visibility.Hidden;
            }
            else
            {
                MessageBox.Show(_user.Info.Message);
                this.Close();
            }

            pnlMainContent.Children.Clear();
            pnlMainContent.Children.Add(new FeedView(this.Api));
        }
Beispiel #2
0
        public IActionResult RegisterUser(RegisterUser newuser)
        {
            User CheckEmail = _iContext.users
                              .Where(u => u.email == newuser.email)
                              .SingleOrDefault();

            if (CheckEmail != null)
            {
                ViewBag.errors = "That email already exists";
                return(RedirectToAction("Register"));
            }
            if (ModelState.IsValid)
            {
                PasswordHasher <RegisterUser> Hasher = new PasswordHasher <RegisterUser>();
                User newUser = new User
                {
                    user_id    = newuser.user_id,
                    first_name = newuser.first_name,
                    last_name  = newuser.last_name,
                    email      = newuser.email,
                    phone      = newuser.phone,
                    password   = Hasher.HashPassword(newuser, newuser.password)
                };
                _iContext.Add(newUser);
                _iContext.SaveChanges();
                ViewBag.success = "Successfully registered";
                return(RedirectToAction("Login"));
            }
            else
            {
                return(View("Register"));
            }
        }
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            btnCreate.IsEnabled = false;
            btnReset.IsEnabled  = false;

            try
            {
                using (var context = new InstaContext())
                {
                    var task = new TaskModel
                    {
                        Name     = txtName.Text,
                        TaskType = (TaskType)comboTaskType.SelectedItem,
                        Searches = SelectedSearches,
                        Schedule = context.Schedules.FirstOrDefault(sc => sc.Id == (int)comboSchedule.SelectedValue),
                        Repeat   = int.Parse(txtRepeatCount.Text)
                    };

                    task.SetValues(this.Values);
                    var user = context.Users.Include("Tasks").FirstOrDefault(u => u.Id == this.User.Id);
                    user.Tasks.Add(task);
                    context.SaveChanges();
                    MessageBox.Show("Task: " + task.Name + " created successfully.");
                }

                Reset();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            btnCreate.IsEnabled = true;
            btnReset.IsEnabled  = true;
        }
 private void BtnStop_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to stop this task premenantly?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
     {
         using (var context = new InstaContext())
         {
             context.Tasks.FirstOrDefault(t => t.Id == this.Item.Id).Exectued = this.Item.Repeat + 1;
             context.SaveChanges();
         }
     }
 }
Beispiel #5
0
        public IActionResult RequestUser(RequestFriend req)
        {
            if (ActiveUser == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            Friend request = new Friend
            {
                friend_id        = req.friend_id,
                is_friend        = req.is_friend,
                requested        = req.requested,
                accepted_request = req.accepted_request,
                user_id          = ActiveUser.user_id
            };

            _iContext.friends.Add(request);
            _iContext.SaveChanges();
            ViewBag.user = ActiveUser;
            return(RedirectToAction("Users", "Friend"));
        }
Beispiel #6
0
 public IActionResult ProcessAddProfile(int user_id, string profile_img, string location, string background_img, string occupation, string skills, string recent_jobs)
 {
     if(ActiveUser == null)
     {
         return RedirectToAction("Login", "Home");
     }
     User user = _iContext.users.Where(u => u.user_id == user_id).SingleOrDefault();
     user.profile_img = profile_img;
     user.location = location;
     user.background_img = background_img;
     user.occupation = occupation;
     user.skills = skills;
     user.recent_jobs = recent_jobs;
     _iContext.SaveChanges();
     return Redirect("/Profile/" + user_id);
 }
        public TEntity Add(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(Add)} entity must not be null");
            }

            try
            {
                 _instaContext.Add(entity);
                 _instaContext.SaveChanges();

                return entity;
            }
            catch (Exception)
            {
                throw new Exception($"{nameof(entity)} could not be saved");
            }
        }
Beispiel #8
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            btnLogin.IsEnabled     = false;
            progressBar.Visibility = Visibility.Visible;

            await Task.Run(() =>
            {
                try
                {
                    using (var context = new InstaContext())
                    {
                        context.Database.CreateIfNotExists();
                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });

            btnLogin.IsEnabled     = true;
            progressBar.Visibility = Visibility.Collapsed;
        }
Beispiel #9
0
 public IActionResult ProcessNewPhoto(AddPhoto add)
 {
     if (ActiveUser == null)
     {
         return(RedirectToAction("Login", "Home"));
     }
     if (ModelState.IsValid)
     {
         Photo photo = new Photo
         {
             user_id     = ActiveUser.user_id,
             image       = add.image,
             img_alt     = add.img_alt,
             description = add.description
         };
         _iContext.photos.Add(photo);
         _iContext.SaveChanges();
         return(RedirectToAction("Dashboard", "Insta"));
     }
     return(View("AddNewPhoto"));
 }
Beispiel #10
0
 public void Save()
 {
     db.SaveChanges();
 }