Exemplo n.º 1
0
        public CategoryMonthKey(IncomeCategory category)
        {
            EntityType = nameof(IncomeCategory);
            EntityID   = category.EntityID;

            FirstDayOfMonth = category.Month.FirstDayOfMonth();
        }
Exemplo n.º 2
0
        public async Task Handle(
            DateTimeOffset date, UserId user, BrokerId broker, AccountId account,
            decimal amount, IncomeCategory category, AssetId?asset)
        {
            if (amount == 0)
            {
                throw new InvalidPriceException();
            }
            if (string.IsNullOrWhiteSpace(category.ToString()))
            {
                throw new InvalidCategoryException();
            }
            var state       = _stateManager.ReadState(date, user);
            var brokerState = state.Brokers.FirstOrDefault(b => b.Id == broker);

            if (brokerState == null)
            {
                throw new BrokerNotFoundException();
            }
            if (brokerState.Accounts.All(a => a.Id != account))
            {
                throw new AccountNotFoundException();
            }
            if ((asset != null) && brokerState.Inventory.All(a => a.Id != asset))
            {
                throw new AssetNotFoundException();
            }
            var id = new OperationId(_idGenerator.GenerateNewId());
            await _stateManager.AddCommand(new AddIncomeCommand(
                                               date, user, broker, account, id, amount, category, asset));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateIncome(CreateIncomeCategoryViewModel createIncome)
        {
            string userId = _userManager.GetUserId(User);

            if (ModelState.IsValid)
            {
                IncomeCategory incomeCategory = _mapper.Map <IncomeCategory>(createIncome);
                incomeCategory.UserId = userId;
                await _balanceService.AddIncomeCategory(incomeCategory);

                return(RedirectToAction("Index", "Category"));
            }

            var expenseCategories = await _balanceService.GetUserExpenseCategories(userId);

            var incomeCategories = await _balanceService.GetUserIncomeCategories(userId);

            CategoryViewModel categoryViewModel = new CategoryViewModel
            {
                CreateExpense     = new CreateExpenseCategoryViewModel(),
                CreateIncome      = createIncome,
                ExpenseCategories = _mapper.Map <IReadOnlyList <ExpenseCategory>, List <ItemCategoryViewModel> >(expenseCategories),
                IncomeCategories  = _mapper.Map <IReadOnlyList <IncomeCategory>, List <ItemCategoryViewModel> >(incomeCategories)
            };

            return(View("Index", categoryViewModel));
        }
        public ActionResult Delete(int accountId, int id)
        {
            IncomeCategory newIncomeCategory = IncomeCategory.Find(id);

            newIncomeCategory.Delete();
            return(RedirectToAction("Show", "Account", new { id = accountId }));
        }
        public ActionResult Update(string newName, double newTotal, int id)
        {
            IncomeCategory newIncomeCategory = IncomeCategory.Find(id);

            newIncomeCategory.Edit(newName, newTotal);
            return(RedirectToAction("Show", newIncomeCategory));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("IncomeCategoryId,Label")] IncomeCategory incomeCategory)
        {
            if (id != incomeCategory.IncomeCategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(incomeCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!IncomeCategoryExists(incomeCategory.IncomeCategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(incomeCategory));
        }
        public ActionResult Create(int accountId, string incomeCategoryName, double total, int id)

        {
            IncomeCategory newIncomeCategory = new IncomeCategory(accountId, incomeCategoryName, total);

            newIncomeCategory.Save();
            return(RedirectToAction("Show", "Account", new { id = accountId }));
        }
Exemplo n.º 8
0
        public ViewResult EditIncomeCategory(int id)
        {
            ViewBag.FormTitle = "Edit Income Type";

            IncomeCategory cat = _incomeCatRepo.Categories.Where(x => x.ID == id).FirstOrDefault();

            return(View(cat));
        }
Exemplo n.º 9
0
 public Income(string name, double absoluteValue, bool periodical, IncomeCategory category, double frequency)
 {
     Name          = name;
     AbsoluteValue = absoluteValue;
     Periodical    = periodical;
     Category      = category;
     Frequency     = frequency;
 }
        public IHttpActionResult RemoveOldIncomeCategory(IncomeCategory oldbooktypetoremove)
        {
            IncomeCategory getincomecategorytoremove = unitOfWork.incomecategories.Get(oldbooktypetoremove.Id);

            getincomecategorytoremove.IsTerminated = true;
            unitOfWork.incomecategories.Update(p => p.Id == getincomecategorytoremove.Id, getincomecategorytoremove);
            unitOfWork.Complete();
            return(Ok("Income Category removed Successfully"));
        }
Exemplo n.º 11
0
 public void Update(IncomeCategory incomeCategory)
 {
     var dbCat = _context.IncomeCategories.FirstOrDefault(ec => ec.Id == incomeCategory.Id);
     if (dbCat != null)
     {
         dbCat.Name = incomeCategory.Name;
     }
     _context.SaveChanges();
 }
Exemplo n.º 12
0
        public void Equals_All_Fields_Same()
        {
            var first  = new IncomeCategory(0, "name");
            var second = new IncomeCategory(0, "name");

            Assert.AreNotSame(first, second);
            Assert.IsTrue(first.Equals(second));
            Assert.IsTrue(second.Equals(first));
        }
Exemplo n.º 13
0
        public void Equals_Name_Differs()
        {
            var first  = new IncomeCategory(0, "name");
            var second = new IncomeCategory(0, "other name");

            Assert.AreNotSame(first, second);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));
        }
Exemplo n.º 14
0
 public void Create(IncomeCategory incomeCategory)
 {
     if (incomeCategory == null)
     {
         return;
     }
     _context.IncomeCategories.Add(incomeCategory);
     _context.SaveChanges();
 }
 public void Create(IncomeCategory incomeCategory)
 {
     if (incomeCategory == null)
     {
         return;
     }
     _context.IncomeCategories.Add(incomeCategory);
     _context.SaveChanges();
 }
        public ActionResult Edit(int accountId, int id)
        {
            Dictionary <string, object> model = new Dictionary <string, object>();
            Account        account            = Account.Find(accountId);
            IncomeCategory newIncomeCategory  = IncomeCategory.Find(id);

            model.Add("account", account);
            model.Add("newIncomeCategory", newIncomeCategory);
            return(View(model));
        }
Exemplo n.º 17
0
 public Income(double amount, DateTime date, IncomeCategory incomeCategory,
     PaymentMethod paymentMethod, string comment, int id = 0)
 {
     this.Amount = amount;
     this.Category = incomeCategory;
     this.Comment = comment;
     this.Date = date;
     this.ID = id;
     this.Method = paymentMethod;
 }
Exemplo n.º 18
0
        public void CreateNewIncomeCategory(string categoryName)
        {
            ApplicationUser user     = db.Users.Find(HttpContext.Current.User.Identity.GetUserId());
            IncomeCategory  category = new IncomeCategory();

            category.Category    = categoryName;
            category.HouseholdId = user.HouseholdId.Value;
            db.IncomeCategories.Add(category);
            db.SaveChanges();
        }
Exemplo n.º 19
0
 public Income(decimal amount, DateTime date, IncomeCategory incomeCategory,
     PaymentMethod paymentMethod, string comment, int id = 0)
 {
     Amount = amount;
     Category = incomeCategory;
     Comment = comment;
     Date = date;
     Id = id;
     Method = paymentMethod;
 }
        public void Update(IncomeCategory incomeCategory)
        {
            var dbCat = _context.IncomeCategories.FirstOrDefault(ec => ec.Id == incomeCategory.Id);

            if (dbCat != null)
            {
                dbCat.Name = incomeCategory.Name;
            }
            _context.SaveChanges();
        }
 public void Save(IncomeCategory incomeCategory)
 {
     if (incomeCategory.Id != 0)
     {
         Update(incomeCategory);
     }
     else
     {
         Create(incomeCategory);
     }
 }
Exemplo n.º 22
0
        public async Task <IActionResult> Create([Bind("IncomeCategoryId,Label")] IncomeCategory incomeCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(incomeCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(incomeCategory));
        }
        public async Task <IActionResult> Put(string id, [FromBody] IncomeCategory category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(GetErrorFromModelState()));
            }

            await _categoryService.UpdateAsync(id, category);

            return(Ok(category));
        }
        public async Task <IActionResult> Post([FromBody] IncomeCategory category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(GetErrorFromModelState()));
            }

            await _categoryService.InsertAsync(category);

            return(Ok(category));
        }
Exemplo n.º 25
0
        private static void BuildIncCatParameter(IncomeCategory incCat, string statement)
        {
            if (statement == "update")
            {
                cmd.Parameters.Add(new SqlParameter("@id", incCat.Id));
            }

            cmd.Parameters.Add(new SqlParameter("@name", incCat.Name));
            cmd.Parameters.Add(new SqlParameter("@description", incCat.Description));
            cmd.Parameters.Add(new SqlParameter("@statusid", incCat.StatusID));
        }
Exemplo n.º 26
0
 public void Save(IncomeCategory incomeCategory)
 {
     if (incomeCategory.Id != 0)
     {
         Update(incomeCategory);
     }
     else
     {
         Create(incomeCategory);
     }
 }
Exemplo n.º 27
0
        public async Task CreateComunication(Income income, IncomeCategory incomeCategory)
        {
            var incCategory = new IncCategory()
            {
                IncomeId         = income.Id,
                IncomeCategoryId = incomeCategory.Id
            };

            _context.IncCategories.Add(incCategory);
            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Get(string id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(GetErrorFromModelState()));
            }

            IncomeCategory value = await _categoryService.GetByIdAsync(id);

            return(Ok(value));
        }
Exemplo n.º 29
0
        public void AddIncomeCategory(IncomeCategory category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            category.Id = new Guid();

            _context.IncomeCategories.Add(category);
        }
        public void ExpenseCategpryRepository_Save_Id_Zero_Adds_Item()
        {
            var mock = RepositoryMocks.GetMockIncomeCategoryRepository();
            var before = mock.GetAll();
            Assert.IsTrue(before.Count() == 0);

            var newItem = new IncomeCategory(0, "test");
            mock.Save(newItem);

            var after = mock.GetAll();
            Assert.IsTrue(after.Contains(newItem));
        }
        public async Task <IActionResult> Create([FromBody] IncomeCategory incomeCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _unitOfWork.IncomeCategory.AddAsync(incomeCategory);

            await _unitOfWork.CompleteAsync();

            return(Ok(incomeCategory));
        }
Exemplo n.º 32
0
 private void IncomeCategoryEntityConfig_EntityUpdated(EntityChangeEvent[] changeEvents)
 {
     foreach (var updatedItem in changeEvents.Select(x => x.Entity))
     {
         IncomeCategory updatedIncomeCategory = updatedItem as IncomeCategory;
         //Если хотябы одна необходимая статья обновилась можем обнлять весь список.
         if (updatedIncomeCategory != null && updatedIncomeCategory.IncomeDocumentType == IncomeInvoiceDocumentType.IncomeTransferDocument)
         {
             UpdateIncomeCategories();
             return;
         }
     }
 }
        public void IncomeCategoryRepository_Create_Adds_New_Item()
        {
            var testObject = new IncomeCategory(0, "test");

            var mock = RepositoryMocks.GetMockIncomeCategoryRepository();
            mock.Create(testObject);

            var result = mock.GetAll();
            Assert.IsTrue(result.Contains(testObject));

            var singleItem = mock.GetById(testObject.Id);
            Assert.IsNotNull(singleItem);
            Assert.AreEqual(testObject, singleItem);
        }
Exemplo n.º 34
0
        public void IncomeCategory_Copy()
        {
            var first = new IncomeCategory
            {
                Id   = 1,
                Name = "Arbitrary Income"
            };

            var second = first.Copy();

            Assert.AreNotSame(first, second);
            Assert.IsTrue(first.Equals(second));
            Assert.IsTrue(second.Equals(first));
        }
Exemplo n.º 35
0
        private void ExecuteContributionCategoryDelete(IncomeCategory category)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                using (var unitofWork = new UnitOfWork(new MahalluDBContext())) {
                    ContributionCategoryList.Remove(category);
                    eventAggregator.GetEvent <PubSubEvent <ObservableCollection <IncomeCategory> > >().Publish(ContributionCategoryList);
                    var result = unitofWork.IncomeCategories.Find((x) => x.Id == category.Id).FirstOrDefault();
                    unitofWork.IncomeCategories.Remove(result);
                    unitofWork.Complete();
                }
            }
        }
Exemplo n.º 36
0
        public async Task <IncomeCategory> CreateIncomeCategoryAsync(IncomeCategory incomeCategory)
        {
            var existedCategory = await _unitOfWork.IncomeCategoryRepository.SingleOrDefaultAsync(u => u.Name == incomeCategory.Name);

            if (existedCategory != null)
            {
                return(null);
            }
            incomeCategory.ImageId = 1;
            await _unitOfWork.IncomeCategoryRepository.AddAsync(incomeCategory);

            await _unitOfWork.Complete();

            return(incomeCategory);
        }
Exemplo n.º 37
0
 private void ExecuteAddContributionCategory()
 {
     using (var unitofWork = new UnitOfWork(new MahalluDBContext())) {
         var category = new IncomeCategory()
         {
             Name = ContributionCategoryText, DetailsRequired = ContributionDetailsRequired
         };
         unitofWork.IncomeCategories.Add(category);
         ContributionCategoryList.Add(category);
         eventAggregator.GetEvent <PubSubEvent <ObservableCollection <IncomeCategory> > >().Publish(ContributionCategoryList);
         ContributionCategoryText    = String.Empty;
         ContributionDetailsRequired = default(bool);
         unitofWork.Complete();
     }
 }
Exemplo n.º 38
0
 public void AddNewCategory(IncomeCategory category)
 {
     _repository.Create(category);
 }
Exemplo n.º 39
0
 private static IncomeCategory readIncomeCategory(SqlDataReader reader)
 {
     IncomeCategory retData = new IncomeCategory((int)reader["ID"])
     {
         Name = (string)reader["Name"]
     };
     return retData;
 }
Exemplo n.º 40
0
 public void Save(IncomeCategory category)
 {
     _repository.Save(category);
 }
Exemplo n.º 41
0
        internal static IncomeCategory SaveIncomeCategory(IncomeCategory data)
        {
            using (SqlConnection con = new SqlConnection(_ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("dbo.IncomeCategoriesSave", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter idParam = cmd.Parameters.Add("@ID", SqlDbType.Int);
                idParam.Value = data.ID;
                SqlParameter nameParam = cmd.Parameters.Add("@Name", SqlDbType.VarChar, 80);
                nameParam.Value = data.Name;

                con.Open();
                SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                while (reader.Read())
                {
                    data = readIncomeCategory(reader);
                }

                reader.Close();
            }

            return data;
        }
Exemplo n.º 42
0
        internal static bool DeleteIncomeCategories(IncomeCategory data)
        {
            bool retData = false;

            using (SqlConnection con = new SqlConnection(_ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("dbo.IncomeCategoryDelete", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter idParam = cmd.Parameters.Add("@ID", SqlDbType.Int);
                idParam.Value = data.ID;

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                retData = true;
            }

            return retData;
        }
Exemplo n.º 43
0
 public void Update(IncomeCategory incomeCategory)
 {
     _context.IncomeCategories.Attach(incomeCategory);
     _context.SaveChanges();
 }
        public void IncomeCategoryRepository_Save_New_Item_With_Non_Zero_Id_Does_Nothing()
        {
            var mock = RepositoryMocks.GetMockIncomeCategoryRepository();

            var before = mock.GetAll();
            Assert.IsTrue(before.Count() == 0);

            var expected = mock.GetById(baseTestData.Id);
            Assert.IsNull(expected);
            expected = new IncomeCategory(1, "save-test");
            mock.Save(expected);

            var after = mock.GetAll();
            Assert.IsTrue(after.Count() == 0);
        }
Exemplo n.º 45
0
 public void Create(IncomeCategory incomeCategory)
 {
     _context.IncomeCategories.Add(incomeCategory);
     _context.SaveChanges();
 }