public BusinessObject <BudgetUser> Get(int id) { using (var db = DBConnection.GetConnection()) { return(BudgetUser.GetById(db, id)); } }
public async Task <IActionResult> Register([FromBody] RegisterRequest model) { if (ModelState.IsValid) { var user = new BudgetUser { UserName = model.Email, Email = model.Email }; try { var result = await _userManager.CreateAsync(user, model.Password); var roleResult = await _userManager.AddToRoleAsync(user, "Admin"); if (result.Succeeded && roleResult.Succeeded) { _logger.LogInformation(3, "User created a new account with password."); return(Ok()); } return(BadRequest(result)); } catch (Exception e) { return(BadRequest(e)); } } return(BadRequest()); }
private async Task <UserProfileProperty> ProcessNewProfileProperty(UserProfileProperty existingUserProfileProperty, UserProfileProperty userProfileProperty, ProfileProperty profileProperty, bool evaluateUnique, string lockName, UserProfilePropertyLogic userProfilePropertyLogic, bool isAdmin) { if (string.IsNullOrEmpty(userProfileProperty.Value)) { // If the update is empty and the user profile property doesn't exist return a blank profile entry. return(existingUserProfileProperty); } if (existingUserProfileProperty.ProfilePropertyName.ToLower() == "email") { BudgetUser cascadeCall = null; cascadeCall = await CascadeEmail(userProfileProperty); // cascade call failed, return if (cascadeCall == null) { return(existingUserProfileProperty); } await CreateProfileProperty(userProfileProperty, profileProperty, evaluateUnique, lockName); } else { await CreateProfileProperty(userProfileProperty, profileProperty, evaluateUnique, lockName); } // Now that the property exists, grab it with definition info. UserProfileProperty updatedUserProfileProperty = await userProfilePropertyLogic.GetUserProfileProperty(userProfileProperty.UserId, userProfileProperty.ProfilePropertyId, isAdmin); return(updatedUserProfileProperty); }
public object AddUser(BudgetUser user) { var b = db.Budgets.FirstOrDefault(x => x.Id == user.BudgetId); var bu = db.BudgetUsers .Include(x => x.User) .FirstOrDefault(x => x.BudgetId == b.Id && x.UserId == user.UserId); if (bu != null) { return(new { ok = false, message = $"User with email {bu.User.Email} already added!", }); } db.BudgetUsers.Add(user); db.SaveChanges(); return(new { ok = true, message = "", }); }
public ActionResult DeleteConfirmed(int id) { BudgetUser budgetUser = db.BudgetUsers.Find(id); db.BudgetUsers.Remove(budgetUser); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <BudgetUser> CreateUser(BudgetUser user) { using (var uow = new UnitOfWork(Context)) { var repo = new UserRepository(uow); return(await repo.Create(user)); } }
public async Task UpdateDBUser(BudgetUser user) { using (var uow = new UnitOfWork(Context)) { var repo = new UserRepository(uow); await repo.Update(user); } }
public async Task UpdateUserRecordUsername(int userId, string newUsername) { UserLogic userLogic = new UserLogic(Cache, Context); BudgetUser user = await userLogic.GetDBUser(userId); user.Username = newUsername; await userLogic.UpdateDBUser(user); }
public ActionResult Edit([Bind(Include = "BudgetUserId,LastName,FirstName,DateOfBirth,AddressLine1,AddressLine2,Town,Counties,Country,PostCode,ContactNo")] BudgetUser budgetUser) { if (ModelState.IsValid) { db.Entry(budgetUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(budgetUser)); }
public BudgetUser VerifyLogin([FromBody] BudgetUser user) { using (var db = DBConnection.GetConnection()) { var userModel = BudgetUser.GetByUserName(db, user.UserName); if (userModel != null && userModel.Password.Equals(user.Password)) { return(userModel); } return(null); } }
// GET: BudgetUsers/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BudgetUser budgetUser = db.BudgetUsers.Find(id); if (budgetUser == null) { return(HttpNotFound()); } return(View(budgetUser)); }
private async Task <BudgetUser> GetUser(int userId) { var userCache = new UserCacheLogic(Cache); BudgetUser user = await userCache.GetUserFromCache(userId); if (user != null) { return(user); } user = await GetDBUser(userId); await userCache.AddUserToCache(user); return(user); }
private async Task <BudgetUser> CascadeEmail(UserProfileProperty userProfileProperty) { BudgetUser getUser = null; BudgetUser updatedUser = null; using (var uow = new UnitOfWork(Context)) { var repo = new UserRepository(uow); getUser = await repo.Find(userProfileProperty.UserId); if (getUser != null) { getUser.Email = userProfileProperty.Value; updatedUser = await repo.Update(getUser); } return(updatedUser); } }
//private async Task SendUserProfilePropertyUpdatedEvent(UserProfileProperty userProfileProperty) //{ // var message = new UserProfilePropertyUpdated // { // UserProfilePropertyId = userProfileProperty.UserProfilePropertyId, // UserId = userProfileProperty.UserId, // ProfilePropertyId = userProfileProperty.ProfilePropertyId, // ProfilePropertyName = userProfileProperty.ProfilePropertyName, // Level = Level // }; // await QueueSender.SendMessage<UserProfilePropertyUpdated>(message); //} private async Task <UserProfileProperty> ProcessExistingProfileProperty(UserProfileProperty existingUserProfileProperty, UserProfileProperty userProfileProperty, ProfileProperty profileProperty, bool evaluateUnique, string lockName) { if (userProfileProperty.DateUpdated != default && existingUserProfileProperty.DateUpdated > userProfileProperty.DateUpdated) { // Don't update if LastUpdated is before the existing. return(existingUserProfileProperty); } if (existingUserProfileProperty.Value == userProfileProperty.Value) { // Values match, don't update. return(existingUserProfileProperty); } // Cascade email profile update to user email if (existingUserProfileProperty.ProfilePropertyName.ToLower() == "email") { BudgetUser cascadeCall = null; cascadeCall = await CascadeEmail(userProfileProperty); if (cascadeCall != null) { var updatedUserProfileProperty = await UpdateExistingProfileProperty(userProfileProperty, existingUserProfileProperty, profileProperty, evaluateUnique, lockName); return(updatedUserProfileProperty); } else { // cascade failed, stop and return existing property return(existingUserProfileProperty); } } else { var updatedUserProfileProperty = await UpdateExistingProfileProperty(userProfileProperty, existingUserProfileProperty, profileProperty, evaluateUnique, lockName); return(updatedUserProfileProperty); } }
public async Task ChangeUsername(int userId, string proposedUsername) { if (userId == 1) { throw new CallerException("Host username cannot be changed."); } UserLogic userLogic = new UserLogic(Cache, Context); BudgetUser originalUser = await userLogic.GetUserWithoutRelated(userId); if (originalUser == null) { throw new CallerException("Cannot find user."); } await ValidateUsername(proposedUsername); await UpdateUserRecordUsername(userId, proposedUsername); var userCacheLogic = new UserCacheLogic(Cache); await userCacheLogic.InvalidateUserCache(userId); }
public async Task <BudgetUser> GetUserWithoutRelated(int userId) { UserCacheLogic userCache = new UserCacheLogic(Cache); BudgetUser user = await userCache.GetUserFromCache(userId); if (user != null) { return(user); } var dbUser = await GetDBUser(userId); user = new BudgetUser() { UserId = dbUser.UserId, Username = dbUser.Username }; await userCache.AddUserToCache(user); return(user); }
// ******************** BUDGET ANALYSIS CHARTS ******************** public ActionResult Charts(int?id) { BudgetUser u = new BudgetUser(); // return list of budgets specific to one user u = db.BudgetUsers.Where(user => user.BudgetUserId == id).SingleOrDefault(); var total = from e in db.Budgets where e.BudgetUserId == id select e; int size = total.Count(); // ******************** TOTAL INCOME/EXPENDITURE CHART ******************** object[] income = new object[size]; int c1 = 0; foreach (var item in total) { income[c1] = item.TotalIncome; c1++; } String[] budgetNames = new string[size]; int c2 = 0; foreach (var item in total) { budgetNames[c2] = item.BudgetName; c2++; } object[] expenditure1 = new object[size]; int c3 = 0; foreach (var item in total) { expenditure1[c3] = item.TotalExpenses; c3++; } Highcharts chart1 = new Highcharts("chart1") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Line, MarginRight = 130, MarginBottom = 50, ClassName = "chart1" }) .SetTitle(new Title { Text = " Total Income by Budget ", X = -20 }) .SetSubtitle(new Subtitle { Text = " Monthly Budget Analysis Chart ", X = -20 }) .SetXAxis(new XAxis { Categories = budgetNames }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Income/Expenditure in €" }, PlotLines = new[] { new YAxisPlotLines { Value = 0, Width = 1, Color = ColorTranslator.FromHtml("#808080") } } }) .SetTooltip(new Tooltip { Crosshairs = new Crosshairs(true, true) }) .SetLegend(new Legend { Layout = Layouts.Vertical, Align = HorizontalAligns.Center, VerticalAlign = VerticalAligns.Top, X = -10, Y = 70, BorderWidth = 0 }) //.SetSeries based on totalIncome(income) and totalExpenditure(expenditure1) objects .SetSeries(new[] { new Series { Name = "Total Income", Data = new Data(income) }, new Series { Name = "Total Expenditure", Data = new Data(expenditure1) } }) .SetCredits(new Credits { Enabled = false }); // -------------------- END TOTAL INCOME/EXPENDITURE CHART -------------------- // ******************** BUDGET BALANCE CHART ******************** object[] budBal = new object[size]; int c4 = 0; foreach (var item in total) { budBal[c4] = item.BudgetBalance; c4++; } Highcharts chart2 = new Highcharts("chart2") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Line, MarginRight = 130, MarginBottom = 50, ClassName = "chart2" }) .SetTitle(new Title { Text = " Budget Balances by Budget " }) .SetSubtitle(new Subtitle { Text = " Monthly Budget Analysis Chart " }) .SetXAxis(new XAxis { Categories = budgetNames }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Budget Balance in €" }, PlotLines = new[] { new YAxisPlotLines { Value = 0, Width = 1, Color = ColorTranslator.FromHtml("#808080") } } }) .SetTooltip(new Tooltip { Crosshairs = new Crosshairs(true, true) }) .SetLegend(new Legend { Layout = Layouts.Vertical, Align = HorizontalAligns.Center, VerticalAlign = VerticalAligns.Top, X = -10, Y = 70, BorderWidth = 0 }) //.SetSeries based on Budget Balance objects .SetSeries(new[] { new Series { Name = "Balance", Data = new Data(budBal) } }) .SetCredits(new Credits { Enabled = false }); // -------------------------- END BUDGET BALANCE CHART ------------------------ // ******************* COLUMN BAR CHART - TOTAL EXPENDITURE (Month on Month) ********** // CAR var carExpenseTotal = 0.0; object[] car = new object[size]; int c5 = 0; foreach (var item in total) { car[c5] = item.TotalCarExpenses; carExpenseTotal += (double)item.TotalCarExpenses; c5++; } // calculate average of Car Expense ViewBag.carAverage = carExpenseTotal / size; ViewBag.size = size; // HOUSEHOLD object[] household = new object[size]; int c6 = 0; foreach (var item in total) { household[c6] = item.TotalHouseholdExpenses; c6++; } // PERSONAL object[] personal = new object[size]; int c7 = 0; foreach (var item in total) { personal[c7] = item.TotalPersonalExpenses; c7++; } // TRAVEL object[] travel = new object[size]; int c8 = 0; foreach (var item in total) { travel[c8] = item.TotalTravelExpenses; c8++; } // UTILITY BILLS object[] utilityBill = new object[size]; int c9 = 0; foreach (var item in total) { utilityBill[c9] = item.TotalUtilityBillExpenses; c9++; } Highcharts chart3 = new Highcharts("chart3") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column, MarginRight = 130, MarginBottom = 50, ClassName = "chart3" }) .SetTitle(new Title { Text = " Expenditure Totals (Month-On-Month) " }) .SetSubtitle(new Subtitle { Text = " Monthly Budget Analysis Chart " }) .SetXAxis(new XAxis { Categories = budgetNames }) .SetYAxis(new YAxis { Min = 0, Title = new YAxisTitle { Text = " Expenditure Total in € " } }) .SetLegend(new Legend { Y = 10, }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { PointPadding = 0.2, BorderWidth = 0 } }) .SetSeries(new[] { new Series { Name = "Car Expenses", Data = new Data(car) }, new Series { Name = "Household Expenses", Data = new Data(household) }, new Series { Name = "Personal Expenses", Data = new Data(personal) }, new Series { Name = "Travel Expenses", Data = new Data(travel) }, new Series { Name = "Utility Bill Expenses", Data = new Data(utilityBill) } }) .SetCredits(new Credits { Enabled = false }); // ---------------------------- END OF COLUMN CHART ---------------------------- return(View(new Container(new[] { chart1, chart2, chart3 }))); }
public async Task AddUserToCache(BudgetUser user) { var key = GetCacheKey(user.UserId); await Cache.Insert(key, user, new TimeSpan(CACHE_TIME_IN_HOURS, 0, 0)); }
public ActionResult Forecast(int?id) { BudgetUser u = new BudgetUser(); // return list of budgets specific to one user u = db.BudgetUsers.Where(user => user.BudgetUserId == id).SingleOrDefault(); var total = from e in db.Budgets where e.BudgetUserId == id select e; int size = total.Count(); // ------------------- CHART AND FORECAST CALCULATIONS FOR BUDGET ANALYSIS CHARTS ------------------- // ******************* COLUMN BAR CHART - TOTAL EXPENDITURE (Month on Month) ******************* // Budget Names String[] budgetNames = new string[size]; int c1 = 0; foreach (var item in total) { budgetNames[c1] = item.BudgetName; c1++; } // Income object[] income = new object[size]; int c2 = 0; foreach (var item in total) { income[c2] = item.TotalIncome; c2++; } object[] expenditure1 = new object[size]; int c3 = 0; foreach (var item in total) { expenditure1[c3] = item.TotalExpenses; c3++; } // CAR var carExpenseTotal = 0.0; object[] car = new object[size]; int c5 = 0; foreach (var item in total) { car[c5] = item.TotalCarExpenses; carExpenseTotal += (double)item.TotalCarExpenses; c5++; } // calculate average of car expenses for all user budgets ViewBag.carAverage = carExpenseTotal / size; ViewBag.size = size; // HOUSEHOLD var householdExpenseTotal = 0.0; object[] household = new object[size]; int c6 = 0; foreach (var item in total) { household[c6] = item.TotalHouseholdExpenses; householdExpenseTotal += (double)item.TotalHouseholdExpenses; c6++; } // calculate average of the household expenses for all user budgets ViewBag.householdAverage = householdExpenseTotal / size; ViewBag.size = size; // PERSONAL var personalExpenseTotal = 0.0; object[] personal = new object[size]; int c7 = 0; foreach (var item in total) { personal[c7] = item.TotalPersonalExpenses; personalExpenseTotal += (double)item.TotalPersonalExpenses; c7++; } // calculate average of the personal expenses for all user budgets ViewBag.personalAverage = personalExpenseTotal / size; ViewBag.size = size; // TRAVEL var travelExpenseTotal = 0.0; object[] travel = new object[size]; int c8 = 0; foreach (var item in total) { travel[c8] = item.TotalTravelExpenses; travelExpenseTotal += (double)item.TotalTravelExpenses; c8++; } // calculate average of the travel expenses for all user budgets ViewBag.travelAverage = travelExpenseTotal / size; ViewBag.size = size; // UTILITY BILLS var utilityBillExpenseTotal = 0.0; object[] utilityBill = new object[size]; int c9 = 0; foreach (var item in total) { utilityBill[c9] = item.TotalUtilityBillExpenses; utilityBillExpenseTotal += (double)item.TotalUtilityBillExpenses; c9++; } // calculate average of the utility bill expenses for all user budgets ViewBag.utilityBillAverage = utilityBillExpenseTotal / size; ViewBag.size = size; Highcharts chart3 = new Highcharts("chart3") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column, MarginRight = 130, MarginBottom = 50, ClassName = "chart3" }) .SetTitle(new Title { Text = " Expenditure Totals (Month-On-Month) " }) .SetSubtitle(new Subtitle { Text = " Monthly Budget Analysis Chart " }) .SetXAxis(new XAxis { Categories = budgetNames }) .SetYAxis(new YAxis { Min = 0, Title = new YAxisTitle { Text = " Expenditure Total in € " } }) .SetLegend(new Legend { Y = 10, }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { PointPadding = 0.2, BorderWidth = 0 } }) .SetSeries(new[] { new Series { Name = "Monthly Income", Data = new Data(income) }, new Series { Name = "Monthly Expenditure", Data = new Data(expenditure1) } }) .SetCredits(new Credits { Enabled = false }); // ---------------------------- END OF COLUMN CHART ---------------------------- // DRILLDOWN string[] categories = { "Income", "Expenditure" }; const string NAME = "Forecast"; Data data = new Data(new[] { new Point { Y = 55.11, Color = Color.FromName("colors[0]"), Drilldown = new Drilldown { Name = "Monthly Income", Categories = new[] { "Car", "Household", "Personal", "Travel", "Utility Bill" }, Data = new Data(new object[] { 10.85, 7.35, 33.06, 2.81 }), Color = Color.FromName("colors[0]") } }, new Point { Y = 21.63, Color = Color.FromName("colors[1]"), Drilldown = new Drilldown { Name = "Monthly Expenditure", Categories = new[] { "Car", "Household", "Personal", "Travel", "Utility Bill" }, Data = new Data(new object[] { car, household, personal, travel, utilityBill }), Color = Color.FromName("colors[1]") } }, }); Highcharts chart = new Highcharts("chart") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column }) .SetTitle(new Title { Text = "Browser market share, April, 2011" }) .SetSubtitle(new Subtitle { Text = "Click the columns to view versions. Click again to view brands." }) .SetXAxis(new XAxis { Categories = categories }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Total percent market share" } }) .SetLegend(new Legend { Enabled = false }) .SetTooltip(new Tooltip { Formatter = "TooltipFormatter" }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { Cursor = Cursors.Pointer, Point = new PlotOptionsColumnPoint { Events = new PlotOptionsColumnPointEvents { Click = "ColumnPointClick" } }, DataLabels = new PlotOptionsColumnDataLabels { Enabled = true, Color = Color.FromName("colors[0]"), Formatter = "function() { return this.y +'%'; }", Style = "fontWeight: 'bold'" } } }) .SetSeries(new Series { Name = "Browser brands", Data = data, Color = Color.White }) .SetExporting(new Exporting { Enabled = false }) .AddJavascripFunction( "TooltipFormatter", @"var point = this.point, s = this.x +':<b>'+ this.y +'% market share</b><br/>'; if (point.drilldown) { s += 'Click to view '+ point.category +' versions'; } else { s += 'Click to return to browser brands'; } return s;" ) .AddJavascripFunction( "ColumnPointClick", @"var drilldown = this.drilldown; if (drilldown) { // drill down setChart(drilldown.name, drilldown.categories, drilldown.data.data, drilldown.color); } else { // restore setChart(name, categories, data.data); }" ) .AddJavascripFunction( "setChart", @"chart.xAxis[0].setCategories(categories); chart.series[0].remove(); chart.addSeries({ name: name, data: data, color: color || 'white' });", "name", "categories", "data", "color" ) .AddJavascripVariable("colors", "Highcharts.getOptions().colors") .AddJavascripVariable("name", "'{0}'".FormatWith(NAME)) .AddJavascripVariable("categories", JsonSerializer.Serialize(categories)) .AddJavascripVariable("data", JsonSerializer.Serialize(data)); return(View(chart3)); }
// ******************** BUDGET ANALYSIS CHARTS ******************** public ActionResult Charts(int?id) { BudgetUser u = new BudgetUser(); // return list of budgets specific to one user u = db.BudgetUsers.Where(user => user.BudgetUserId == id).SingleOrDefault(); var total = from e in db.Budgets where e.BudgetUserId == id select e; int size = total.Count(); // System.Diagnostics.Debug.WriteLine("size: " + size); // DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart") object[] income = new object[size]; int c1 = 0; foreach (var item in total) { income[c1] = item.TotalIncome; c1++; } String[] budgetNames = new string[size]; int c2 = 0; foreach (var item in total) { budgetNames[c2] = item.BudgetName; c2++; } int value = 0; Highcharts chart = new Highcharts("chart") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Line, MarginRight = 130, MarginBottom = 25, ClassName = "chart" }) .SetTitle(new Title { Text = "Monthly Budget Analysis Charts " }) .SetSubtitle(new Subtitle { Text = " Total Income Analysis Chart " }) .SetXAxis(new XAxis { Categories = budgetNames //Categories = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Total Income in €" }, PlotLines = new[] { new YAxisPlotLines { Value = 0, Width = 1, Color = ColorTranslator.FromHtml("#808080") } } }) .SetTooltip(new Tooltip { Crosshairs = new Crosshairs(true, true) }) .SetLegend(new Legend { Layout = Layouts.Vertical, Align = HorizontalAligns.Right, VerticalAlign = VerticalAligns.Top, X = -10, Y = 100, BorderWidth = 0 }) //.SetSeries(new Series .SetSeries(new [] { new Series { Name = "Total Income", Data = new Data(income) } //Data = new Data(new object[] { 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4 }) }) .SetCredits(new Credits { Enabled = false }); // remove hyperlink for highchart return(View(chart)); }