public ViewCollectionLogViewModel()
        {
            userCollectionModel = new UserCollectionModel();
            GetCollectionLogs();

            CollectionEntryDate = DateTime.Today;
        }
Example #2
0
        public IActionResult AddAlbumToCollection(long?id)
        {
            var user  = _context.Users.Single(x => x.UserName == User.Identity.Name);
            var album = _context.Albums.Single(x => x.Id == id);

            _context.Entry(album).Collection(x => x.Song).Load();

            foreach (var song in album.Song)
            {
                var userCollectionModel = new UserCollectionModel();

                userCollectionModel.User = user;
                userCollectionModel.Song = song;

                if (_context.UserCollections
                    .Where(x => x.SongId == id && x.UserId == user.Id)
                    .Count() == 0)
                {
                    try
                    {
                        _context.Add(userCollectionModel);
                        _context.SaveChanges();
                    }
                    catch { }
                }
            }

            return(Redirect("/Album/Details/" + id));
        }
        void GetUserBasedOnID(object parameter)
        {
            if (userCollectionModel == null)
            {
                userCollectionModel = new UserCollectionModel();
            }
            ObservableCollection <User> userList = new ObservableCollection <User>();

            if (SearchUserID.IsEmpty() == false)
            {
                var searchUserList = userCollectionModel.GetUserBasedOnID(SearchUserID);
                if (searchUserList.IsEmpty() == false)
                {
                    SelectedUserName       = searchUserList[0].UserName;
                    SelectedUserPendingAmt = (Int64)searchUserList[0].CurrentAmt;
                    //UserList = UserList.Where(a=>a.ID=SearchUserID).ToList();
                    UserList = userCollectionModel.GetUserList(start, itemCount, sortColumn, ascending, SearchUserID, out totalItems);
                    NotifyPropertyChanged("Start");
                    NotifyPropertyChanged("End");
                    NotifyPropertyChanged("TotalItems");
                }
                else
                {
                    MessageBox.Show("User ID is not present");
                }
            }
            else
            {
                MessageBox.Show("Enter User ID to search");
            }
        }
Example #4
0
        public IActionResult AddOrRemoveCollection(long?id)
        {
            var userCollectionModel = new UserCollectionModel();

            var user = _context.Users.Single(x => x.UserName == User.Identity.Name);

            userCollectionModel.User = user;
            userCollectionModel.Song = _context.Songs.Single(x => x.Id == id);

            if (_context.UserCollections
                .Where(x => x.SongId == id && x.UserId == user.Id)
                .Count() == 0)
            {
                _context.Add(userCollectionModel);
                _context.SaveChanges();
            }
            else
            {
                _context.Remove(userCollectionModel);
                _context.SaveChanges();
            }

            _context.Entry(userCollectionModel.Song).Reference(x => x.Album).Load();
            var album = _context.Albums.Single(x => userCollectionModel.Song.Album.Id == x.Id);

            return(Redirect("/Album/Details/" + album.Id));
        }
 private void GetUserLogGrid()
 {
     if (userCollectionModel == null)
     {
         userCollectionModel = new UserCollectionModel();
     }
     UserList = userCollectionModel.GetUserList(start, itemCount, sortColumn, ascending, searchID, out totalItems);
     // userList = new ObservableCollection<User>(userCollectionModel.GetUserList(), start, itemCount, sortColumn, ascending, out totalItems);
     NotifyPropertyChanged("Start");
     NotifyPropertyChanged("End");
     NotifyPropertyChanged("TotalItems");
 }
        public UserCollectionViewModel()
        {
            if (userCollectionModel == null)
            {
                userCollectionModel = new UserCollectionModel();
            }
            GetUserLogGrid();
            int openingBalanceFromDB = userCollectionModel.GetOpeningBalance();

            OpeningAccountBalance = openingBalanceFromDB;
            EntryDate             = DateTime.Today;
        }
 public void GetCollectionLogs()
 {
     //CollectionLogList = new ObservableCollection<CollectionEntry>(userCollectionModel.GetCollectionLog());
     if (userCollectionModel == null)
     {
         userCollectionModel = new UserCollectionModel();
     }
     CollectionLogList = userCollectionModel.GetCollectionsLog(start, itemCount, ascending, userID, selectedDate, out totalItems);
     // userList = new ObservableCollection<User>(userCollectionModel.GetUserList(), start, itemCount, sortColumn, ascending, out totalItems);
     NotifyPropertyChanged("Start");
     NotifyPropertyChanged("End");
     NotifyPropertyChanged("TotalItems");
 }
 void ClearField([Optional] object parameter)
 {
     if (userCollectionModel == null)
     {
         userCollectionModel = new UserCollectionModel();
     }
     UserList               = userCollectionModel.GetUserList(start, itemCount, sortColumn, ascending, searchID, out totalItems);
     SearchUserID           = "";
     SelectedUserName       = "";
     SelectedUserPendingAmt = 0;
     CollectionAmt          = 0;
     EntryDate              = DateTime.Today;
 }
Example #9
0
        public async Task <IActionResult> UserCollectionPost(UserCollectionModel model)
        {
            var post = await PostSvc.GetByIdAsync(model.PostId);

            if (post == null)
            {
                return(new JsonResult(new APIResult <long> {
                    ErrorMsg = "帖子不存在"
                })
                {
                    StatusCode = 400
                });
            }
            return(new JsonResult(new APIResult <long> {
                Data = await PostSvc.UserCollectionPostAsync(model.UserId, model.PostId)
            }));
        }
        void AddUser(object parameter)
        {
            User userFields = new User()
            {
                ID            = id,
                UserName      = userName,
                Address       = address,
                Mobile        = mobile,
                InitialAmt    = initialAmt,
                DateOfJoining = dateOfJoining,
                InterestRate  = interestAmt,
                CurrentAmt    = currentAmt
            };

            if (id == null || userName == null || address == null || mobile == null || initialAmt == null || dateOfJoining == null || currentAmt == null)
            {
                MessageBox.Show("Fill in all the mandatory fields");
            }
            else
            {
                userModel          = new UserCollectionModel();
                userFields.DueDate = userFields.DateOfJoining.AddDays(100);
                List <User> userIDAvailable = userModel.GetUserBasedOnID(id);
                double      accountBalance  = financeModel.GetAccountBalance();
                if (accountBalance > currentAmt)
                {
                    if (userIDAvailable.IsEmpty())
                    {
                        financeModel.AddEmployee(userFields);
                        MessageBox.Show("Data Saved Successfully.");
                        ClearField();
                    }
                    else
                    {
                        MessageBox.Show("User ID is already present");
                    }
                }
                else
                {
                    MessageBox.Show("Account Balance is low and maximum amount is " + accountBalance);
                }
            }
        }
        public async Task <IActionResult> Collection(UserCollectionModel model)
        {
            long userId = Convert.ToInt64(HttpContext.Session.GetString(ConstList.USERID));

            if (await RedisHelper.SIsMemberAsync($"collection_{userId}", model.PostId))
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "不能重复收藏帖子"
                }));
            }
            model.UserId = userId;
            if (!await PostSvc.UserCollectionPostAsync(model))
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = PostSvc.ErrorMsg
                }));
            }
            await RedisHelper.SAddAsync($"collection_{userId}", model.PostId);

            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }
        void DailyAmountLog(object parameter)
        {
            CollectionEntry dailyCollectionAmt = new CollectionEntry()
            {
                ID         = SearchUserID,
                UserName   = SelectedUserName,
                EntryDate  = EntryDate,
                BalanceAmt = SelectedUserPendingAmt,
                CurrentAmt = CollectionAmt
            };

            if (SearchUserID == null || SelectedUserName == null || EntryDate == null || SelectedUserPendingAmt.HasValue == false ||
                CollectionAmt.HasValue == false || SelectedUserName.IsVoid() || CollectionAmt <= 0 || SelectedUserPendingAmt <= 0)
            {
                MessageBox.Show("Fill in all the mandatory fields");
            }
            else
            {
                if (userCollectionModel == null)
                {
                    userCollectionModel = new UserCollectionModel();
                }
                string selectedDate   = (string.Format("{0:yyyy-MM-dd H:mm:ss}", dailyCollectionAmt.EntryDate));
                string userEntryExist = userCollectionModel.CheckEntryForSameDate(dailyCollectionAmt.ID, selectedDate);
                if (userEntryExist.IsVoid())
                {
                    userCollectionModel.DailyCollectionEntry(dailyCollectionAmt);
                    SelectedUserPendingAmt = SelectedUserPendingAmt - CollectionAmt;
                    ClearField();
                }
                else
                {
                    MessageBox.Show("Amount is already entered for the user");
                }
            }
        }
        /// <summary>
        /// 用户收藏帖子
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <bool> UserCollectionPostAsync(UserCollectionModel model)
        {
            SDKResult result = await client.PutAsync("UserCollectionPost", model);

            JObject obj = JsonConvert.DeserializeObject <JObject>(result.Result);

            if (result.StatusCode == System.Net.HttpStatusCode.BadRequest)
            {
                ErrorMsg = obj["errorMsg"].ToString();
                return(false);
            }
            else if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(true);
            }
            else if (result.StatusCode == System.Net.HttpStatusCode.NoContent)
            {
                return(true);
            }
            else
            {
                throw new ApplicationException("未知的错误");
            }
        }