private Budget CreateBudget(BudgetViewModel viewModel) { var budget = new Budget(); _budgetMapper.Map(viewModel, budget); return(budget); }
public async Task <ActionResult> AddProduct(BudgetViewModel model) { if (ModelState.IsValid) { // quantity <= stock siempre se debe hacer var product = await db.Products.FindAsync(model.ProductId); if (product == null) { TempData["ErrorMessage"] = "Producto no encontrado"; return(RedirectToAction("Edit", new { id = model.BudgetId })); } if (product.ProductStock < model.Quantity) { TempData["ErrorMessage"] = $"No hay stock suficiente, nos quedan {product.ProductStock} unidades "; return(RedirectToAction("Edit", new { id = model.BudgetId })); } var budgetProduct = new BudgetProduct { ProductId = model.ProductId, Price = product.ProductPrice, BudgetId = model.BudgetId, Quantity = model.Quantity }; db.BudgetProducts.Add(budgetProduct); await db.SaveChangesAsync(); TempData["SuccessMessage"] = "Se agrego correctamente el producto"; return(RedirectToAction("Edit", new { id = model.BudgetId })); } TempData["ErrorMessage"] = "Faltan datos requeridos"; return(RedirectToAction("Edit", new { id = model.BudgetId })); }
public async Task <IActionResult> UpdateBudget(int budgetId, [FromBody] BudgetViewModel model) { int roomieId = int.Parse(HttpContext.User.FindFirst(c => c.Type == ClaimTypes.NameIdentifier).Value); Result result = await _budgetGateway.UpdateBudget(budgetId, model.CategoryId, model.Date1, model.Date2, model.Amount, model.CollocId); return(this.CreateResult(result)); }
public BudgetViewModel CreateFirstBudgetViewModel() { BudgetViewModel myBudget = new BudgetViewModel(); myBudget.HasBudget = false; return(myBudget); }
// GET: Budget public ActionResult Budget() { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("login", "Home")); } UserRepository UserRepo = new UserRepository(Properties.Settings.Default._connectionString); User CurrentUser = UserRepo.GetUserByEmail(User.Identity.Name); BudgetRepository BudgetRepo = new BudgetRepository(Properties.Settings.Default._connectionString); var BudgetModel = new BudgetViewModel(); BudgetModel.CurrentUser = BudgetRepo.UserWithHistory(CurrentUser.Id); BudgetModel.MonthsBudgeted = BudgetRepo.MonthYearForUser(CurrentUser.Id); BudgetModel.AllCategories = BudgetRepo.GetAllCategories(); if (BudgetModel.MonthsBudgeted.Count != 0) { //gets debits for last month budgeted BudgetModel.DebitsForLatestMonth = BudgetRepo.GetDebitsByMonthId(CurrentUser.Id, BudgetModel.MonthsBudgeted[BudgetModel.MonthsBudgeted.Count - 1].Id); BudgetModel.CreditsForLastMonth = BudgetRepo.GetCreditsByMonthId(CurrentUser.Id, BudgetModel.MonthsBudgeted[BudgetModel.MonthsBudgeted.Count - 1].Id); BudgetModel.LatestMonth = BudgetRepo.GetMonthInfo(BudgetModel.MonthsBudgeted[BudgetModel.MonthsBudgeted.Count - 1].Id); } return(View(BudgetModel)); }
public IActionResult AddJson(BudgetViewModel model) { try { if (ModelState.IsValid) { var result = BudgetManager.Add(model, CurrentUser); return(Json(new { success = true, Budget = result })); } } catch (Exception e) { var innerMessage = e.InnerException == null ? "" : $": {e.InnerException.Message}"; ModelState.AddModelError("", e.Message + innerMessage); } return(Json(new { success = false, errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); }
/// <summary> /// Gets collection of SelectListItem for select field in View with opened budgets /// </summary> /// <param name="selectedBudget">Budget which will be selected</param> /// <returns>collection of SelectListItem for select field in View with opened budgets</returns> public IEnumerable <SelectListItem> GetOpenBudgetsItemList(BudgetViewModel selectedBudget = null) { var budgetsItemList = BudgetManager.GetBudgets(IncludeLevel.None) .Where(x => x.Status == Status.Opened) .OrderByDescending(x => x.CreatedDate) .Select(x => new SelectListItem(x.BudgetNumber, x.Id)); if (selectedBudget != null) { budgetsItemList = budgetsItemList .Where(x => x.Value != selectedBudget.Id) .Union(new List <SelectListItem>() { new SelectListItem(selectedBudget.BudgetNumber, selectedBudget.Id, true) }); } else { budgetsItemList = budgetsItemList.Union(new List <SelectListItem>() { new SelectListItem(null, null, true) }); } return(budgetsItemList); }
public async Task <IActionResult> GetBudget([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Budget budget = await _context.Budget .Where(i => i.Id == id) .Include(i => i.BudgetLabels) .ThenInclude(budgetLabel => budgetLabel.Label) .FirstOrDefaultAsync(); if (budget == null) { return(NotFound()); } BudgetViewModel budgetVM = new BudgetViewModel { Id = budget.Id, Bedrag = budget.Bedrag, Begindatum = budget.Begindatum, Einddatum = budget.Einddatum, Interval = budget.Interval, Label = toLabelViewModelList(budget.BudgetLabels) }; return(Ok(budgetVM)); }
public async Task <IActionResult> Create(BudgetViewModel view) { if (ModelState.IsValid) { try { if (await ValidateBudget(view)) { Budget budget = this.ToBudget(view); budget.ID = 0; context.Add(budget); await context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { budget.ID })); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } } view.Areas = combosHelper.GetComboAreas(); return(View(view)); }
public UpdateBudgetCommandTest() { _budgetViewModel = new BudgetViewModel { Income = 45.3m, StartDate = new DateTime(2014, 8, 1), Categories = new[] { new BudgetCategoryViewModel { Name = "Home", LineItems = new[] { new BudgetLineItemViewModel { Actual = 54, Estimate = 23, Name = "Mortgage" } } } } }; _budget = new Budget { StartDate = new DateTime(_budgetViewModel.Year, _budgetViewModel.Month, 1), Categories = new List <Category>() }; _budgetRepository = new InMemoryRepository <Budget>(); _budgetRepository.Insert(_budget).Wait(); _updateBudgetCommand = new UpdateBudgetCommand(_budgetRepository); }
public ActionResult ListAll(string errorMessage, bool showAll = false) { var model = new BudgetListViewModel(userManager.GetRoles(User.Identity.GetUserId())); IEnumerable <Budget> budgets = null; if (showAll) { model.Error = errorMessage; budgets = budgetRepository.Where(b => b.Client.IsActive).OrderBy(b => b.IsHandled).ThenBy(b => b.Month).ToList(); } else { var currentUserId = User.Identity.GetUserId(); model.Error = errorMessage; budgets = budgetRepository.Where(b => b.Client.IsActive && (b.Client.AccountManagerId == currentUserId || b.Client.ConsultantId == currentUserId)).OrderBy(b => b.IsHandled).ThenBy(b => b.Month).ToList(); } foreach (var budget in budgets) { var budgetViewModel = new BudgetViewModel(budget); model.Budgets.Add(budgetViewModel); } if (User.IsInRole("consultant")) { model.CanMarkBudgetAsDone = true; } else { model.CanMarkBudgetAsDone = false; } return(View(model)); }
public ActionResult Get(int id) { var budget = GetBudget(id); var viewModel = new BudgetViewModel(budget, Db); return(Json(viewModel.Flatten(), JsonRequestBehavior.AllowGet)); }
public ActionResult Budget(BudgetSearchViewModel search) { var Projects = Projectservice.Get(); Projects.Insert(0, new ProjectsViewModel() { Id = 0, Name = "All" }); ViewBag.Projects = Projects; var inc = new BudgetSearchViewModel(); var outc = new OutcomesearchViewModel(); var incomes = Incomeservice.Get(search); var Outcomes = Outcomeservice.Get(search); ViewBag.Search = search; var items = new BudgetViewModel() { Incomes = incomes, Outcomes = Outcomes, IncomesTotal = incomes.Sum(i => i.Cost), OutcomesTotal = Outcomes.Sum(i => i.Cost), }; return(View(items)); }
private List <BudgetViewModel> BudgetAdjustmentCommon() { var lstBudget = new List <BudgetViewModel>(); var budgetList = _repAnnualBudget.GetBudgetList().OrderByDescending(x => x.Id).ToList(); foreach (var item in budgetList) { var bvm = new BudgetViewModel() { Year = item.Year, BudgetProvision = item.BudgetProvision, ExceedProvision = item.ExceedProvision, TotalProvision = item.BudgetProvision + _repAnnualBudget.GetExceedProvision(item.Id), UsedBudget = _repAnnualBudget.GetUsedBudget(item.Id), RemainingAmount = item.BudgetProvision + _repAnnualBudget.GetExceedProvision(item.Id) - _repAnnualBudget.GetUsedBudget(item.Id), StartDate = item.StartDate, EndDate = item.EndDate, Status = item.Status }; lstBudget.Add(bvm); } return(lstBudget); }
public ActionResult Index() { BudgetViewModel objBudget = new BudgetViewModel(); int CurrentMonth = DateTime.Today.Month; int CurrentYear = DateTime.Today.Year; // Set Current Year if (CurrentMonth == 1 || CurrentMonth == 2 || CurrentMonth == 3) { objBudget.YearId = CurrentYear - 1; } else { objBudget.YearId = CurrentYear; } objBudget.MonthId = DateTime.Today.ToString("MMMM"); objBudget.Months = CommonRepository.FillMonthsDropDownList(CommonConstants.MonthsName); // objBudget.BusinessVerticals = CommonRepository.FillMonthsDropDownList(CommonConstants.BusinessVerticals); objBudget.Projects = new SelectList(_IBudgetService.GetProjects(), "ProjectID", "ProjectName", "select"); objBudget.Years = GetYear(); return(View(objBudget)); }
public async Task Post() { BudgetViewModel budgetVM = GenerateTestModel(); var response = await this.Client.PostAsync(URI, new StringContent(JsonConvert.SerializeObject(budgetVM).ToString(), Encoding.UTF8, "application/json")); Assert.Equal(HttpStatusCode.Created, response.StatusCode); }
private BudgetViewModel[] GetBudgetViewModels(string projectId) { var budgets = ProjectService.GetProjectBudgets(projectId) .Select(b => new BudgetViewModel(b)) .ToDictionary(b => b.Category, b => b); var categorys = Enum.GetValues(typeof(BudgetCategory)); foreach (int category in categorys) { if (!budgets.ContainsKey(category)) { var entity = new Budget() { ProjectId = projectId, Category = category, Amount = 0 }; entity = ProjectService.AddBudget(entity); budgets.Add(entity.Category, new BudgetViewModel(entity)); } } var expenditures = ProjectService.GetProjectExpenditures(projectId); BudgetViewModel budget = null; foreach (var expenditure in expenditures) { if (budgets.TryGetValue(expenditure.BudgetCategory, out budget)) { budget.Expenditures.Add(expenditure); } } return(budgets.Values.OrderBy(q => q.Category).ToArray()); }
public ActionResult Create(BudgetViewModel model, int month = 1, int year = 2017) { model.DATETIME = DateTime.Now; //BudgetDb.insert(model); BudgetDb.Add(model); return(RedirectToAction("Index")); }
private async Task <bool> IsExistingBudget(BudgetViewModel viewModel) { var budgets = await _budgetRepository.GetAll(); return(budgets .Where(b => b.StartDate.Month == viewModel.Month) .Any(b => b.StartDate.Year == viewModel.Year)); }
public BudgetPage() { InitializeComponent(); BindingContext = viewModel = new BudgetViewModel(); //ButtonView.IsVisible = false; }
public AddBudgetCommandTest() { _budgetViewModel = new BudgetViewModel { Categories = new BudgetCategoryViewModel[0] }; _budgetRepository = new InMemoryRepository <Budget>(); _addBudgetCommand = new AddBudgetCommand(_budgetRepository); }
private Task NotifyClientsBudgetDataChanged(BudgetViewModel budgetViewModel, CancellationToken cancellationToken) { return(_hubContext.Clients.All.SendAsync( "SendNotification", "Budget data updated", budgetViewModel, cancellationToken)); }
public BudgetViewModel GetEmptyData() { BudgetViewModel Data = new BudgetViewModel(); Data.name = ""; Data.code = ""; return(Data); }
public ActionResult Index() { var model = new BudgetViewModel(); model.Budgets = db.Budgets.Include(b => b.Household); model.Categories = db.Categories.Include(c => c.Household); return(View(model)); }
/// <summary> /// Gets BudgetViewModel based on budget for given Id or throws exceptions if budget not found. /// </summary> /// <param name="budgetId">Budget id</param> /// <returns>BudgetViewModel based on budget for given Id</returns> public BudgetViewModel GetBudgetViewModelById(string budgetId) { var budget = GetBudgetById(budgetId, IncludeLevel.Level2); var model = new BudgetViewModel(budget); return(model); }
public IActionResult GetTest() { var budgetVM = new BudgetViewModel { budgets = _budget.GetAllBudget() }; return(View(budgetVM)); }
//public async Task<IActionResult> CreateDetails(Budget budget) //{ // if (budget.BudgetCategory.Count == 0) // { // return RedirectToAction("Edit", new { id = budget.BudgetId }); // } // BudgetViewModel model = new BudgetViewModel(); // model.Budget = budget; // model.BudgetCategories = await _context.BudgetCategory.Where(bc => bc.BudgetId == budget.BudgetId).ToListAsync(); // return View(model); //} public IActionResult CreateDetails(BudgetViewModel model) { if (model.BudgetCategories == null || model.BudgetCategories.Count == 0) { return(RedirectToAction("Edit", new { id = model.Budget.BudgetId })); } return(View(model)); }
public BudgetingPage(FundViewModel fundView, ExpenseViewModel expenseView) { var expenseStore = new SQLiteExpenseStore(DependencyService.Get <ISQLiteDb>()); var fundStore = new SQLiteFundStore(DependencyService.Get <ISQLiteDb>()); var pageService = new PageService(); ViewModel = new BudgetViewModel(pageService, fundView ?? new FundViewModel(), fundStore, expenseView ?? new ExpenseViewModel(), expenseStore); InitializeComponent(); }
private BudgetViewModel TranslateToBudgetViewModel(BudgetItemListViewModel budgetItemListViewModel) { BudgetViewModel budgetViewModel = new BudgetViewModel(); if (budgetItemListViewModel != null && budgetItemListViewModel.BudgetItemList != null && budgetItemListViewModel.BudgetItemList.Count > 0) { budgetViewModel.ClientID = budgetItemListViewModel.ClientID; budgetViewModel.MonthlyBudget = budgetItemListViewModel.MonthlyBudget; foreach (BudgetItemViewModel bivm in budgetItemListViewModel.BudgetItemList) { switch (bivm.ItemName.ToLower()) { case "savings": budgetViewModel.Saving = bivm.ItemPercent; break; case "housing": budgetViewModel.Housing = bivm.ItemPercent; break; case "transportation": budgetViewModel.Transportation = bivm.ItemPercent; break; case "utilities": budgetViewModel.Utilities = bivm.ItemPercent; break; case "food": budgetViewModel.Food = bivm.ItemPercent; break; case "clothing": budgetViewModel.Clothing = bivm.ItemPercent; break; case "misc": budgetViewModel.Misc = bivm.ItemPercent; break; case "personal": budgetViewModel.Personal = bivm.ItemPercent; break; case "recreation": budgetViewModel.Recreation = bivm.ItemPercent; break; case "debt": budgetViewModel.Debt = bivm.ItemPercent; break; } } } return(budgetViewModel); }
private void UpdateMemoryCache(BudgetViewModel budgetViewModel) { _memoryCache.Set( CacheKeys.CacheKeyForBudgetId(budgetViewModel.BudgetId), budgetViewModel, new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(1) }); }
public MainWindowViewModel() { Tree = new ObservableCollection<BudgetViewModel>(); BudgetViewModel budget = new BudgetViewModel(new BudgetModel("11", "ololo", PokazatelType.Budget)); budget.AddChild(new PokazatelModel("111", "srgrth", 1, 2)); budget.AddChild(new PokazatelModel("222", "sdgtrhrtf", 0, 0)); budget.AddChild(new PokazatelModel("333", "dvdfbfdb", 0, 2)); budget.AddChild(new PokazatelModel("444", "vdrbtfaeh", 1, 0)); budget.AddChild("555", "sgrthsrt", PokazatelType.Budget); budget.Children.Last().AddChild(new PokazatelModel("666", "verbrbe", 1, 2)); budget.Children.Last().AddChild("777", "rgrwegg", PokazatelType.Budget); budget.Children.Last().Children.Last().AddChild(new PokazatelModel("999", "sgasegwgr", 2, 2)); budget.Children.Last().Children.Last().AddChild("234", "reghbs", PokazatelType.Budget); budget.Children.Last().Children.Last().Children.Last().AddChild(new PokazatelModel("1242", "sefs", 1, 2)); budget.Children.Last().Children.Last().Children.Last().AddChild(new PokazatelModel("25235", "9g23", 1, 2)); budget.Children.Last().Children.Last().Children.Last().AddChild(new PokazatelModel("2341", "9gds23", 2, 2)); budget.Children.Last().Children.Last().AddChild(new PokazatelModel("923", "gerg", 1, 2)); budget.Children.Last().AddChild(new PokazatelModel("888", "erthrjsa", 1, 2)); //BudgetViewModel budget = new BudgetViewModel(new BudgetModel("ololo1", PokazatelType.Ciaz)); //budget.AddChild(new PokazatelModel("111", 1)); //budget.AddChild(new PokazatelModel("222", 1)); //budget.AddChild(new PokazatelModel("333", 1)); //budget.AddChild(new PokazatelModel("444", 1)); //budget.AddChild("555", PokazatelType.Ciaz); //budget.Children.Last().AddChild(new PokazatelModel("666", 1)); //budget.Children.Last().AddChild("777", PokazatelType.Ciaz); //budget.Children.Last().Children.Last().AddChild(new PokazatelModel("999", 2)); //budget.Children.Last().Children.Last().AddChild("234", PokazatelType.Ciaz); //budget.Children.Last().Children.Last().Children.Last().AddChild(new PokazatelModel("sefs", 1)); //budget.Children.Last().Children.Last().Children.Last().AddChild(new PokazatelModel("9g23", 1)); //budget.Children.Last().Children.Last().Children.Last().AddChild(new PokazatelModel("9gds23", 2)); //budget.Children.Last().Children.Last().AddChild(new PokazatelModel("923", 1)); //budget.Children.Last().AddChild(new PokazatelModel("888", 1)); //budget.IsSelected = true; budget.IsExpanded = true; budget.IsSelected = true; budget.IsRawExpanded = true; Tree.Add(budget); InitializeBudgetCommands(); }
public BudgetViewModel(BudgetModel BudgetModel, BudgetViewModel parent) { this.BudgetModel = BudgetModel; this.Pokazatel = new PokazatelViewModel(BudgetModel.Pokazatel); this.RawPokazatel = new PokazatelViewModel(BudgetModel.Pokazatel); Difference = new PokazatelViewModel(BudgetModel.Difference); this.Parent = parent; this.Children = new ObservableCollection<BudgetViewModel>(); this.Type = BudgetModel.Type; }
public BudgetPage() { this.InitializeComponent(); this.budgetVM = new BudgetViewModel(); }
/// <summary> /// Получает самого корневого предка в дереве /// </summary> public BudgetViewModel GetRootParent(BudgetViewModel parent = null) { if (parent == null) { if (this.Parent != null) return GetRootParent(this.Parent); else return this; } else { if (parent.Parent != null) return GetRootParent(parent.Parent); else return parent; } }
/// <summary> /// Используется для рекурсивного поиска выделеного елемента для свойства SelectedItem /// </summary> /// <param name="parent"></param> /// <returns></returns> private BudgetViewModel GetSelectedChild(BudgetViewModel parent) { foreach (BudgetViewModel child in parent.Children) { if (child.IsSelected) { //SelectedItem = child; return child; } BudgetViewModel tempItem = GetSelectedChild(child); if (tempItem != null) { //SelectedItem = tempItem; return tempItem; } } //SelectedItem = null; return null; }
/// <summary> /// Указывает выделеный елемент всем предкам до самого корневого предка в дереве /// </summary> public void SetSelectedItemTillRootParent() { if (this.Parent != null) { this.Parent.SelectedItem = this.SelectedItem; this.Parent.SetSelectedItemTillRootParent(); } }