public bool createJob(Jobs job) { _context.jobs.Add(job); _context.SaveChanges(); return(true); }
public ActionResult Create(Student student, Guid cons) { if (ModelState.IsValid) { student.Id = Guid.NewGuid(); student.CId = cons; db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public bool add(Attachments attachment) { try { _context.docs.Add(attachment); _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public bool add(Units unit) { try { _context.units.Add(unit); _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
protected override void Seed(FitnessViewer.Infrastructure.Data.ApplicationDb context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // using (ApplicationDb db = new ApplicationDb()) { // if no data in calendar then populate it. 1980->2050 should be plenty if (db.Calendar.ToList().Count == 0) { DateTime date = new DateTime(1980, 1, 1); List <Calendar> detailsToAdd = new List <Calendar>(); while (date <= new DateTime(2050, 12, 31)) { detailsToAdd.Add(new Calendar(date)); date = date.AddDays(1); } context.Calendar.AddRange(detailsToAdd); db.SaveChanges(); } List <Calendar> nullWeekLabel = db.Calendar.Where(c => c.WeekLabel == null).ToList(); if (nullWeekLabel.Count > 0) { foreach (Calendar cal in nullWeekLabel) { // populate WeekLabel property. cal.UpdateValuesForDate(); // update db.Calendar.Attach(cal); var entry = db.Entry(cal); entry.Property(c => c.WeekLabel).IsModified = true; db.SaveChanges(); } } } }
public ActionResult Edit([Bind(Include = "UserID,Name,Age,Phone,Email,ApplicationUserId")] UserAcount userAcount) { var userId = User.Identity.GetUserId(); var checkingStudentId = db.UserAcounts.Where(c => c.ApplicationUserId == userId).First().UserID; if (ModelState.IsValid) { db.Entry(userAcount).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userAcount)); }
public CommandResult <StatusReportItem> Execute(ApplicationDb db) { var statusReportItems = db.StatusReports.Find(this.StatusReportId).StatusReportItems.ToList(); StatusReportItem item = db.StatusReportItems.Create(); item.StatusReportId = this.StatusReportId; item.StatusReportCategoryId = this.StatusReportCategoryId; item.Description = this.Description; item.Sequence = statusReportItems.Count > 0 ? statusReportItems.Max(i => i.Sequence) + 1 : 1; db.StatusReportItems.Add(item); db.SaveChanges(); // add tags from hashtags in description var hashTags = this.Description.GetHashTags(); db.UpdateStatusItemTags(hashTags, item); Tag tag; StatusReportItemTag statusReportItemTag; // add tags from array if (this.Tags != null) { foreach (var tagName in this.Tags) { tag = db.Tags.Where(t => t.Name == tagName).SingleOrDefault(); if (tag == null) { // create the tag first tag = db.Tags.Create(); tag.Name = tagName; db.Tags.Add(tag); db.SaveChanges(); } statusReportItemTag = db.StatusReportItemTags.Create(); statusReportItemTag.TagId = tag.TagId; statusReportItemTag.StatusReportItemId = item.StatusReportItemId; db.StatusReportItemTags.Add(statusReportItemTag); db.SaveChanges(); } } return(new CommandResult <StatusReportItem> { Data = item, ResultCode = "0", ResultText = "Succesfully new report item." }); }
private Athlete CreateAthlete(ApplicationDb context, Athlete athlete) { context.Athletes.Add(athlete); context.SaveChanges(); return(athlete); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var db = new ApplicationDb(); var login = new UserAcount { Name = model.Name, Email = model.Email, Age = model.Age, Phone = model.Phone, ApplicationUserId = user.Id }; db.UserAcounts.Add(login); db.SaveChanges(); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public IActionResult DeleteCategory(int key) { Category category = GetCategories().FirstOrDefault(x => x.CategoryId == key); ApplicationDb.Categories.Remove(category); ApplicationDb.SaveChanges(); return(Ok()); }
public IActionResult DeleteRecurringTransfer(int key) { RecurringTransfer recurringTransfer = GetRecurringTransfers().FirstOrDefault(x => x.RecurringTransferId == key); ApplicationDb.RecurringTransfers.Remove(recurringTransfer); ApplicationDb.SaveChanges(); return(Ok()); }
public IActionResult DeleteTransfer(int key) { Transfer transfer = GetTransfers().FirstOrDefault(x => x.TransferId == key); ApplicationDb.Transfers.Remove(transfer); ApplicationDb.SaveChanges(); return(Ok()); }
private void CreateActivities(ApplicationDb context, List <Activity> activities) { foreach (var activity in activities) { context.Activities.Add(activity); } context.SaveChanges(); }
public ActionResult Create([Bind(Include = "GaneStatID,UserID,GameName,Status,MetaScore,LastPalayed,PlayTime")] GameStats gameStats) { var userId = User.Identity.GetUserId(); var checkingId = db.UserAcounts.Where(c => c.ApplicationUserId == userId).First().UserID; gameStats.UserID = checkingId; gameStats.GameImmage = ""; if (ModelState.IsValid) { db.GameStats.Add(gameStats); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.UserAcounts, "UserID", "Name", gameStats.UserID); return(View(gameStats)); }
public void Add(SysSignalR item) { using (var db = new ApplicationDb()) { db.SysSignalRs.Add(item); db.SaveChanges(); } }
public void Add(SysSignalROnline item) { using (var db = new ApplicationDb()) { db.SysSignalROnlines.Add(item); db.SaveChanges(); } }
public PensionerDetailssController(ApplicationDb context) { _context = context; if (!_context.BankDetails.Any() && !_context.PensionerDetails.Any()) { _context.SeedValues(); _context.SaveChanges(); } }
public IActionResult RemoveData() { ApplicationDb.BalanceReports.RemoveRange(GetBalanceReports()); ApplicationDb.Transfers.RemoveRange(GetTransfers()); ApplicationDb.RecurringTransfers.RemoveRange(GetRecurringTransfers()); ApplicationDb.Categories.RemoveRange(GetCategories()); ApplicationDb.SaveChanges(); return(Ok()); }
public override void Execute(DeleteTeamCommand command, ICommandAndQueryDispatcher dispatcher) { Team team = dispatcher.ExecuteQuery(new GetTeamByIdQuery(command.TeamId)); if (CurrentUserCanDeleteTeams(team, dispatcher)) { db.Teams.Remove(team); db.SaveChanges(); } }
// public async Task<IEnumerable<RolePermission>> InsertRolePermissionAsync(IEnumerable<RolePermission> LtsrolePermission) public async Task <IEnumerable <RolePermission> > InsertRolePermissionAsync(IEnumerable <RolePermission> LtsrolePermission) { try { string _RoleID = "0"; if (LtsrolePermission == null) { return(null); } foreach (var item in LtsrolePermission) { _RoleID = item.RoleId; var Role = await _db.RolePermissions.FirstOrDefaultAsync(x => x.RoleId == _RoleID && x.componentId == item.componentId); if (Role == null) { var _New = new RolePermission { Id = 0, componentId = item.componentId, componentKindCode = item.componentKindCode, componentName = item.componentName, RoleId = item.RoleId, RoleName = item.RoleName, InsertYN = item.InsertYN, UpdateYN = item.UpdateYN, DeleteYN = item.DeleteYN, PrintYN = item.PrintYN, ViewYN = item.ViewYN }; _db.RolePermissions.Add(_New); } else { Role.InsertYN = item.InsertYN; Role.UpdateYN = item.UpdateYN; Role.DeleteYN = item.DeleteYN; Role.PrintYN = item.PrintYN; Role.ViewYN = item.ViewYN; _db.RolePermissions.Update(Role); } } _db.SaveChanges(); var role = await GetRolePermissionAsync(_RoleID); return(role); } catch (Exception ex) { return(null); } }
public void Remove(Expression<Func<SysSignalROnline, bool>> where) { using (var db = new ApplicationDb()) { foreach (var item in db.SysSignalROnlines.Where(where)) { db.SysSignalROnlines.Remove(item); } db.SaveChanges(); } }
public CommandResult <bool> Execute(ApplicationDb db) { Activity activity = db.Activities.Find(this.ActivityId); db.Activities.Remove(activity); db.SaveChanges(); return(new CommandResult <bool> { Data = true, ResultCode = "0", ResultText = "Succesfully created new activity" }); }
public void Remove(Expression <Func <SysSignalROnline, bool> > where) { using (var db = new ApplicationDb()) { foreach (var item in db.SysSignalROnlines.Where(where)) { db.SysSignalROnlines.Remove(item); } db.SaveChanges(); } }
public CommandResult <bool> Execute(ApplicationDb db) { StatusReport statusReport = db.StatusReports.Find(this.StatusReportId); db.StatusReports.Remove(statusReport); db.SaveChanges(); return(new CommandResult <bool> { Data = true, ResultCode = "0", ResultText = "Succesfully deleted status report" }); }
public CommandResult <bool> Execute(ApplicationDb db) { StatusReportItemTag itemTag = db.StatusReportItemTags.Where(t => t.Tag.Name == this.TagName && t.StatusReportItemId == this.StatusReportItemId).SingleOrDefault(); db.StatusReportItemTags.Remove(itemTag); db.SaveChanges(); return(new CommandResult <bool> { Data = true, ResultCode = "0", ResultText = "Succesfully deleted status report item tag." }); }
public CommandResult <bool> Execute(ApplicationDb db) { ActivityTag activityTag = db.ActivityTags.Where(at => at.Tag.Name == this.TagName && at.ActivityId == this.ActivityId).SingleOrDefault(); db.ActivityTags.Remove(activityTag); db.SaveChanges(); return(new CommandResult <bool> { Data = true, ResultCode = "0", ResultText = "Succesfully deleted activity tag." }); }
private ApplicationUser CreateUser(ApplicationDb context, string email, string password) { var hasher = new PasswordHasher(); var user = new ApplicationUser { UserName = email, Email = email, PasswordHash = hasher.HashPassword(password) }; context.Users.AddOrUpdate(user); context.SaveChanges(); return(user); }
public CommandResult <bool> Execute(ApplicationDb db) { StatusReportItem item = db.StatusReportItems.Find(this.StatusReportItemId); db.StatusReportItems.Remove(item); db.SaveChanges(); return(new CommandResult <bool> { Data = true, ResultCode = "0", ResultText = "Succesfully created status report item" }); }
public CommandResult <Trackable> Execute(ApplicationDb db) { Trackable trackable = db.Trackables.Create(); trackable.Description = this.Description; db.Trackables.Add(trackable); db.SaveChanges(); return(new CommandResult <Trackable> { Data = trackable, ResultCode = "0", ResultText = "A new trackable has been created." }); }
public CommandResult <Activity> Execute(ApplicationDb db) { Activity activity = db.Activities.Find(this.ActivityId); activity.Description = this.Description; if (activity.StartDate.Kind == DateTimeKind.Local || activity.StartDate.Kind == DateTimeKind.Unspecified) { activity.StartDate = this.StartDate.ToUniversalTime(); } else { activity.StartDate = this.StartDate; } if (activity.EndDate.HasValue && (activity.EndDate.Value.Kind == DateTimeKind.Local || activity.EndDate.Value.Kind == DateTimeKind.Unspecified)) { activity.EndDate = this.EndDate; } if (!String.IsNullOrEmpty(this.TimeSpent)) { activity.TimeSpent = this.TimeSpent; int timeSpentInMins = 0; // see if we can parse the values if (!Int32.TryParse(this.TimeSpent, out timeSpentInMins)) { // parse timespent d, m, h foreach (Match match in Regex.Matches(this.TimeSpent, @"\d+?d")) { var days = Int32.Parse(match.Value.Substring(0, match.Value.Length - 1)); timeSpentInMins = timeSpentInMins + (days * 24 * 60); } foreach (Match match in Regex.Matches(this.TimeSpent, @"\d+?h")) { var hours = Int32.Parse(match.Value.Substring(0, match.Value.Length - 1)); timeSpentInMins = timeSpentInMins + (hours * 60); } foreach (Match match in Regex.Matches(this.TimeSpent, @"\d+?m")) { var minutes = Int32.Parse(match.Value.Substring(0, match.Value.Length - 1)); timeSpentInMins = timeSpentInMins + minutes; } } activity.TimeSpentMins = timeSpentInMins; } db.SaveChanges(); return(new CommandResult <Activity> { Data = activity, ResultCode = "0", ResultText = "Succesfully updated existing activity" }); }
private void Seed() { using var context = new ApplicationDb(ContextOptions); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var company1 = new CompanyData { Name = "One", Url = "CompanyPageTest.html" }; context.Add(company1); context.SaveChanges(); }
public override void Execute(JoinTeamCommand command, ICommandAndQueryDispatcher dispatcher) { var teamQuery = new GetTeamByIdQuery(command.TeamId); Team team = dispatcher.ExecuteQuery(teamQuery); if (UserIsNotAMemberOfTeam(command.GetUserId, team)) { var userQuery = new GetUserByIdQuery(command.GetUserId); team.Members.Add(new TeamMembership(dispatcher.ExecuteQuery(userQuery), MembershipStatus.Pending)); } db.SaveChanges(); }