Esempio n. 1
0
        public async Task <IActionResult> Add(int walletId)
        {
            try
            {
                var user = await this.userManager.GetUserAsync(this.User);

                if (!await this.walletsService.IsUserOwnWalletAsync(user.Id, walletId))
                {
                    return(this.Redirect($"/Home/Error?message={GlobalConstants.NoPermissionForEditWallet}"));
                }

                AddRecordViewModel model = new AddRecordViewModel();

                var categories = await this.walletsService.GetWalletCategoriesAsync(walletId);

                model.Categories = categories.Select(x => new CategoryNameIdViewModel()
                {
                    Name       = x.Name,
                    Id         = x.Id,
                    WalletName = x.WalletName,
                    BadgeColor = Enum.Parse <BadgeColor>(x.BadgeColor.ToString()),
                });

                model.WalletId   = walletId;
                model.WalletName = await this.walletsService.GetWalletNameAsync(walletId);

                return(this.View(model));
            }
            catch (Exception ex)
            {
                return(this.Redirect($"/Home/Error?message={ex.Message}"));
            }
        }
Esempio n. 2
0
        public async Task AddPostShoudCreateRecordSuccessfully()
        {
            // Arrange
            this.FillDatabase();

            this.inputModel = new AddRecordViewModel
            {
                Amount      = 20,
                WalletId    = 5,
                CategoryId  = 4,
                Type        = ViewModels.Records.Enums.RecordTypeInputModel.Expense,
                Description = "Test Record",
                CreatedOn   = DateTime.UtcNow,
            };

            // Act
            var result = await this.controller.Add(this.inputModel);

            // Assert
            var viewResult = Assert.IsType <RedirectResult>(result);
            var record     = this.db.Records.FirstOrDefault(x => x.Description == "Test Record");

            Assert.Equal("Test Record", record.Description);
            Assert.Equal(4, record.CategoryId);
            Assert.True(record.Type == RecordType.Expense);
            Assert.Equal(-20, record.Amount);
        }
Esempio n. 3
0
        // GET: Record/Create
        public IActionResult Create()
        {
            List <Genre>       genres             = _context.Genres.ToList();
            AddRecordViewModel addRecordViewModel = new AddRecordViewModel(genres);

            return(View(addRecordViewModel));
        }
Esempio n. 4
0
        public IActionResult AddRecord(int ExerciseID, int WorkoutID)
        {//Create form for each exercise to have sets reps and weight to submit
            //!!!!!!!!!!!!!!TAKEN FROM WORKOUT CONTROLLER!!!!!!!!!  MAY NEED CHANGING!!!!!!!!!!!!!!!!
            string          user         = User.Identity.Name;
            ApplicationUser userLoggedIn = context.Users.Single(c => c.UserName == user);

            List <ExerciseWorkout> exercises = context
                                               .ExerciseWorkouts
                                               .Include(item => item.Exercise)
                                               .Where(cm => cm.WorkoutID == ExerciseID && cm.Workout.OwnerId == userLoggedIn.Id)//cm.Workout.OwnerId == userLoggedIn.Id returns list of owner specific workouts
                                               .ToList();

            Workout workout = context.Workouts.Single(m => m.WorkoutID == WorkoutID);

            Exercise exercise = context.Exercises.Single(m => m.ExerciseID == ExerciseID);

            AddRecordViewModel viewModel = new AddRecordViewModel
            {
                Workout   = workout,
                Exercises = exercises,
                Exercise  = exercise
            };

            return(View(viewModel));
        }
Esempio n. 5
0
        public IActionResult AddRecord(AddRecordViewModel addRecordViewModel, int ExerciseID, int WorkoutID)
        {//Create records of exercise sets reps and weights to be added to database.
            if (ModelState.IsValid)
            {
                string          user         = User.Identity.Name;
                ApplicationUser userLoggedIn = context.Users.Single(c => c.UserName == user);
                Record          newRecord    = new Record
                {
                    Sets          = addRecordViewModel.Sets,
                    Reps          = addRecordViewModel.Reps,
                    Weight        = addRecordViewModel.Weight,
                    DateCreated   = DateTime.Now,
                    OwnerId       = userLoggedIn.Id,
                    WorkoutID     = WorkoutID,
                    FK_ExerciseID = ExerciseID
                };
                context.Records.Add(newRecord);
                context.SaveChanges();

                return(Redirect("/Record/ExerciseList/" + WorkoutID));
            }
            else
            {
                return(View(addRecordViewModel));
            }
        }
        public ActionResult AddRecord(int Id)
        {
            AddRecordViewModel model = new AddRecordViewModel();

            model.BandId = Id;

            return(View(model));
        }
Esempio n. 7
0
        // GET: DailyEvents

        public ActionResult DailyRecords()
        {
            //this function adds new record to the table
            AddRecordViewModel CASvm  = new AddRecordViewModel();
            string             userId = User.Identity.GetUserId();

            CASvm.Category        = db.Categories.Where(c => c.UserId == userId).ToList();
            CASvm.Subcategory     = db.Subcategories.Where(s => s.UserId == userId).ToList();
            CASvm.Transaction     = new Transaction();
            CASvm.WalletAndBanks  = db.WalletAndBanks.ToList();
            CASvm.Transactions    = db.Transactions.Where(x => x.AddedDate == DateTime.Today.Date && x.UserId == userId).ToList();
            CASvm.TransactionDate = DateTime.Now;

            return(View(CASvm));
        }
Esempio n. 8
0
        /// <summary>
        /// Const
        /// </summary>
        public AddRecordPage()
        {
            InitializeComponent();

            BindingContext = viewModel = new AddRecordViewModel();

            var ent = new Entry();

            Entry_One.ReturnCommand   = new Command(() => Entry_Two.Focus());
            Entry_Two.ReturnCommand   = new Command(() => Entry_Three.Focus());
            Entry_Three.ReturnCommand = new Command(() => Entry_Four.Focus());
            Entry_Four.ReturnCommand  = new Command(() => Entry_Five.Focus());
            Entry_Five.ReturnCommand  = new Command(() => Entry_Six.Focus());
            Entry_Six.ReturnCommand   = new Command(() => Entry_Seven.Focus());
        }
 public ActionResult AddRecord(AddRecordViewModel model)
 {
     if (ModelState.IsValid)
     {
         bool value = repository.AddRecordToBand(model);
         if (value)
         {
             return(RedirectToAction("RecordList", new { Id = model.BandId }));
         }
         else
         {
             return(View("AddRecord"));
         }
     }
     else
     {
         return(View("AddRecord"));
     }
 }
Esempio n. 10
0
        //NewTransaction Field
        public ActionResult AddTransaction(AddRecordViewModel data)
        {
            var         userId      = User.Identity.GetUserId();
            Transaction transaction = new Transaction()
            {
                TransactionDate = data.TransactionDate,
                AddedDate       = DateTime.Now.Date,
                TransationValue = data.TransactionValue,
                CategoryId      = data.CategoyId,
                SubcategoryId   = data.SubcategoryId,
                WalletAndBankId = data.WalletAndBankId,
                Comment         = data.Comment,
                UserId          = userId
            };

            db.Transactions.Add(transaction);
            db.SaveChanges();
            return(RedirectToAction("DailyRecords"));
        }
Esempio n. 11
0
        public async Task <IActionResult> Add(AddRecordViewModel input)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            try
            {
                if (!this.ModelState.IsValid)
                {
                    if (!await this.walletsService.IsUserOwnWalletAsync(user.Id, input.WalletId))
                    {
                        return(this.Redirect($"/Home/Error?message={GlobalConstants.NoPermissionForEditWallet}"));
                    }

                    var categories = await this.walletsService.GetWalletCategoriesAsync(input.WalletId);

                    input.Categories = categories.Select(x => new CategoryNameIdViewModel()
                    {
                        Name       = x.Name,
                        Id         = x.Id,
                        WalletName = x.WalletName,
                        BadgeColor = Enum.Parse <BadgeColor>(x.BadgeColor.ToString()),
                    });

                    input.WalletName = await this.walletsService.GetWalletNameAsync(input.WalletId);

                    return(this.View(input));
                }

                if (!await this.walletsService.IsUserOwnWalletAsync(user.Id, input.WalletId))
                {
                    return(this.Redirect($"/Home/Error?message={GlobalConstants.NoPermissionForEditWallet}"));
                }

                var enumValueAsString = input.Type.ToString();
                await this.recordsService.AddAsync(input.CategoryId, input.Description, input.Amount, enumValueAsString, input.CreatedOn);

                return(this.Redirect($"/Wallets/Records/{input.WalletId}"));
            }
            catch (Exception ex)
            {
                return(this.Redirect($"/Home/Error?message={ex.Message}"));
            }
        }
Esempio n. 12
0
        //[Bind("RecordId,Artist,Title,Year,NumOfTracks")] Record record
        public async Task <IActionResult> Create(AddRecordViewModel addRecordViewModel)
        {
            if (ModelState.IsValid)
            {
                Genre theGenre = _context.Genres.Find(addRecordViewModel.GenreId);

                Record newRecord = new Record
                {
                    Artist      = addRecordViewModel.Artist,
                    Title       = addRecordViewModel.Title,
                    Year        = addRecordViewModel.Year,
                    NumOfTracks = addRecordViewModel.NumOfTracks,
                    Genre       = theGenre
                };

                _context.Records.Add(newRecord);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(addRecordViewModel));
        }
Esempio n. 13
0
        public ActionResult AddRecord(AddRecordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(400, "Wrong data"));
            }

            using (ForumDBEntities entities = new ForumDBEntities())
            {
                Records record = new Records()
                {
                    Name       = model.Name,
                    Text       = model.Text,
                    SubtopicId = model.SubtopicId,
                    Date       = DateTime.Now,
                    UserId     = entities.UserData.Find(User.Identity.GetUserId()).User.Id
                };

                entities.Records.Add(record);
                entities.SaveChanges();
            }

            return(RedirectToAction("Index", "Home"));
        }
 public AddRecordPage(string tableName)
 {
     this.tableName = tableName;
     InitializeComponent();
     BindingContext = viewModel = new AddRecordViewModel(tableName, App.Database);
 }
Esempio n. 15
0
 public AccountSelectionViewController(AddRecordViewModel addRecordViewModel) : base("AccountSelectionViewController")
 {
     _viewModel          = ServiceLocator.Current.GetInstance <IAccountsSelectionViewModel>();
     _addRecordViewModel = addRecordViewModel;
 }
 public CategorySelectionViewController(AddRecordViewModel addRecordViewModel) : base("CategoriesSelectionViewController")
 {
     _addRecordViewModel = addRecordViewModel;
     _viewModel          = ServiceLocator.Current.GetInstance <ICategorySelectionViewModel>();
 }
Esempio n. 17
0
 public AddRecordPage()
 {
     _addrecordViewModel = ViewModelLocator.AddRecordViewModel;
     InitializeComponent();
     BindingContext = _addrecordViewModel;
 }
Esempio n. 18
0
 public void test()
 {
     viewModel = new AddRecordViewModel("User");
 }