public Budget CreateBudgetFromTemplate(BudgetTemplate template, DateTime startDate) { Budget newBudget = _factory.CreateBudget(template, startDate); _budgetRepository.Persist(newBudget); return(newBudget); }
public BudgetTemplateEditPage() { AddSubcatCommand = new Command <BudgetCategoryForEdit>(category => { var foundCategory = BudgetTemplate.FirstOrDefault(element => category.Id == element.Id); if (foundCategory != null) { var newElement = new BudgetSubcatEdit { Id = foundCategory.Count, IsNew = true }; foundCategory.Add(newElement); Device.BeginInvokeOnMainThread(() => { listView.ScrollTo(newElement, ScrollToPosition.Center, false); OnPropertyChanged(nameof(BudgetTemplate)); }); } }); BudgetTemplate = MainBudget.Instance.BudgetDescription.GetBudgetTemplateEdit(); InitializeComponent(); BindingContext = this; }
public async Task <ActionResult> Details(int?id) { #region USERVALIDATION token = (string)(Session["accessToken"]); string userID = (string)(Session["UserID"]); #endregion if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } List <BudgetTemplate> budgetTemplate = new List <BudgetTemplate>(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseurl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); HttpResponseMessage Res = await client.GetAsync($"api/BudgetTemplates/{id}"); if (Res.IsSuccessStatusCode) { var budgetTemplateResponse = Res.Content.ReadAsStringAsync().Result; BudgetTemplate mybudgetTemplate = JsonConvert.DeserializeObject <BudgetTemplate>(budgetTemplateResponse); return(View(mybudgetTemplate)); } else { this.AddNotification("Unable to display Budget Temnplate information,please contact Administrator" + Res, NotificationType.ERROR); return(View()); } } }
public Budget CreateBudget(BudgetTemplate template, DateTime startDate) { var endDate = default(DateTime); switch (template.Duration) { case Duration.Weekly: endDate = AddWeek(startDate); break; case Duration.Monthly: endDate = AddMonth(startDate); break; case Duration.Quarterly: endDate = Quarterly(startDate); break; case Duration.Yearly: endDate = AddYear(startDate); break; default: throw new ArgumentOutOfRangeException(); } return(new Budget { ValidFrom = startDate, ValidTo = endDate }); }
public async Task <ActionResult> Edit([Bind(Include = "ID,BudgetItem,BudgetItemDesc,PercentageAllocated,OrganizationID,CreatedDate,isDeleted,TimeStamp")] BudgetTemplate budgetTemplate) { if (ModelState.IsValid) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseurl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); HttpResponseMessage Res = await client.PutAsJsonAsync($"api/BudgetTemplates/{budgetTemplate.ID}", budgetTemplate); if (Res.IsSuccessStatusCode) { this.AddNotification("Budget Template information modified successfully", NotificationType.SUCCESS); return(RedirectToAction("Index")); } else { this.AddNotification("Budget Template information cannot be modified at this time. Please contact Administrator", NotificationType.ERROR); return(View()); } } } ViewBag.OrganizationID = await OrganizationSelectListByModel(token, budgetTemplate.OrganizationID); return(View(budgetTemplate)); }
public void UpdateBudgetTemplate_Should_Persist_Budget_Template_In_Repository() { var budgetTemplate = new BudgetTemplate(); _sut.UpdateBudgetTemplate(budgetTemplate); A.CallTo(() => _templateRepository.Persist(budgetTemplate)) .MustHaveHappened(); }
public void Create_Budget_Should_Create_Budget_Using_Factory() { var someTemplate = new BudgetTemplate(); var someDate = DateTime.Today; _sut.CreateBudgetFromTemplate(someTemplate, someDate); A.CallTo(() => _budgetFactory.CreateBudget(someTemplate, someDate)) .MustHaveHappened(); }
public IHttpActionResult CreateTemplate(CreateTemplateModel parameter) { var template = new BudgetTemplate { Duration = parameter.Duration, Name = parameter.Name }; _templateRepository.Persist(template); return(CreatedAtRoute("GetTemplateById", new { id = template.Id }, template)); }
public void UpdateBudgetTemplate_Should_Return_Budget_Template_From_Repository() { var expected = new BudgetTemplate(); A.CallTo(() => _templateRepository.Persist(A <BudgetTemplate> ._)) .Returns(expected); var result = _sut.UpdateBudgetTemplate(new BudgetTemplate()); Assert.That(result, Is.EqualTo(expected)); }
public void Can_Create_Year_From_Template() { var template = new BudgetTemplate(Duration.Yearly, "Yearly Budget"); var expectedStartDate = new DateTime(2016, 1, 1); var expectedEndDate = new DateTime(2016, 12, 31); Budget budget = _budgetFactory.CreateBudget(template, expectedStartDate); Assert.That(budget, Is.Not.Null); Assert.That(budget.ValidFrom, Is.EqualTo(expectedStartDate)); Assert.That(budget.ValidTo, Is.EqualTo(expectedEndDate)); }
public void Can_Create_Quarterly_From_Template() { var template = new BudgetTemplate(Duration.Quarterly, "Quarterly Budget"); var expectedStartDate = new DateTime(2016, 1, 1); var expectedEndDate = new DateTime(2016, 3, 31); Budget budget = _budgetFactory.CreateBudget(template, expectedStartDate); Assert.That(budget, Is.Not.Null); Assert.That(budget.ValidFrom, Is.EqualTo(expectedStartDate)); Assert.That(budget.ValidTo, Is.EqualTo(expectedEndDate)); }
public void Can_Create_Monthly_Budget_From_Template(DateTime expectedStartDate, DateTime expectedEndDate) { // Arrange var template = new BudgetTemplate(Duration.Monthly, "Monthly Budget"); // Act Budget budget = _budgetFactory.CreateBudget(template, expectedStartDate); // Assert Assert.That(budget, Is.Not.Null); Assert.That(budget.ValidFrom, Is.EqualTo(expectedStartDate)); Assert.That(budget.ValidTo, Is.EqualTo(expectedEndDate)); }
public void Can_Create_Weekly_Budget_From_Template() { // Arrange var template = new BudgetTemplate(Duration.Weekly, "Weekly Budget"); var expectedStartDate = new DateTime(2015, 10, 2); var expectedEndDate = new DateTime(2015, 10, 8); // Act Budget budget = _budgetFactory.CreateBudget(template, expectedStartDate); // Assert Assert.That(budget, Is.Not.Null); Assert.That(budget.ValidFrom, Is.EqualTo(expectedStartDate)); Assert.That(budget.ValidTo, Is.EqualTo(expectedEndDate)); }
public void CreateBudgetFromTemplate_By_Template_Id_Should_Persist_Created_Budget_In_Repository() { var someTemplateId = 1; var someTemplate = new BudgetTemplate(); var someBudget = new Budget(); A.CallTo(() => _templateRepository.FindById(someTemplateId)) .Returns(someTemplate); A.CallTo(() => _budgetFactory.CreateBudget(A <BudgetTemplate> ._, A <DateTime> ._)) .Returns(someBudget); _sut.CreateBudgetFromTemplate(someTemplateId, DateTime.Today); A.CallTo(() => _budgetRepository.Persist(someBudget)).MustHaveHappened(); }
public async Task <ActionResult> Create([Bind(Include = "ID,BudgetItem,BudgetItemDesc,PercentageAllocated,OrganizationID,CreatedDate,isDeleted,TimeStamp")] BudgetTemplate budgetTemplate) { #region USERVALIDATION token = (string)(Session["accessToken"]); string userID = (string)(Session["UserID"]); #endregion if (ModelState.IsValid) { budgetTemplate.CreatedDate = DateTime.Now; budgetTemplate.isDeleted = false; budgetTemplate.TimeStamp = DateTime.Now; using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseurl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); HttpResponseMessage Res = await client.PostAsJsonAsync("api/BudgetTemplates", budgetTemplate); if (Res.IsSuccessStatusCode) { this.AddNotification("Budget Template created successfully", NotificationType.SUCCESS); return(RedirectToAction("Index")); } else { this.AddNotification("Budget Template cannot be created at this time. Please contact Administrator" + Res, NotificationType.ERROR); return(View()); } } } ViewBag.OrganizationID = await OrganizationSelectListByModel(token, budgetTemplate.OrganizationID); return(View(budgetTemplate)); }
public async Task <IActionResult> GetBudgetTemplate([FromRoute] int id) { BudgetTemplate bt = budgetTemplates.FirstOrDefault(x => x.Id == id); return(Ok(bt)); }
public BudgetTemplate UpdateBudgetTemplate(BudgetTemplate template) { return(_templateRepository.Persist(template)); }
public void Does_Budget_Have_Proper_Default_Name_When_One_Is_Supplied() { String budget_name = "Weekly Budget"; var template = new BudgetTemplate(Duration.Weekly, budget_name); Budget budget = _budgetFactory.CreateBudget(template, new DateTime(2015, 6, 9)); Assert.That(budget, Is.Not.Null); Assert.That(budget.Name, Is.EqualTo(budget_name)); }
public async Task <IActionResult> PutBT([FromBody] BudgetTemplate budgetTemplate) { budgetTemplates.Add(budgetTemplate); return(Ok()); }
public void Can_Create_Yearly_Budget_From_Template(DateTime expectedStartDate, DateTime expectedEndDate) { var template = new BudgetTemplate(Duration.Yearly, "Quarterly Budget"); Budget budget = _budgetFactory.CreateBudget(template, expectedStartDate); Assert.That(budget, Is.Not.Null); Assert.That(budget.ValidFrom, Is.EqualTo(expectedStartDate)); Assert.That(budget.ValidTo, Is.EqualTo(expectedEndDate)); }