public void ConnectToChat(long profileId, string connectionId) { context.Chat.Add(new Chat { ProfileId = profileId, ConnectionId = connectionId }); context.SaveChanges(); }
public void SaveDisease(Disease disease) { if (disease.DiseaseId == 0) { _dbContext.Diseases.Add(disease); } else { var diseaseEntry = _dbContext.Diseases.SingleOrDefault(x => x.DiseaseId == disease.DiseaseId); if (diseaseEntry == null) { throw new NullReferenceException($"Can't find disease with id {disease.DiseaseId}"); } //_dbContext.Entry(disease).State = EntityState.Modified; diseaseEntry.StartDate = disease.StartDate; diseaseEntry.EndDate = disease.EndDate; diseaseEntry.Person = _dbContext.Persons.SingleOrDefault(x => x.PersonId == disease.Person.PersonId); diseaseEntry.Symptoms = disease.Symptoms; } _dbContext.SaveChanges(); }
public static void InitData(EFDBContext context) { if (!context.Directory.Any()) { context.Directory.Add(new Entities.Directory() { Title = "First Directory", Html = "<b>First Directory Content</b>" }); context.Directory.Add(new Entities.Directory() { Title = "Second Directory", Html = "<b>Second Directory Content</b>" }); context.SaveChanges(); context.Material.Add(new Entities.Material() { Title = "First Material", Html = "<b>First Material Content</b>", DirectoryId = context.Directory.First().Id }); context.Material.Add(new Entities.Material() { Title = "Second Material", Html = "<b>Second Material Content</b>", DirectoryId = context.Directory.First().Id }); context.Material.Add(new Entities.Material() { Title = "Third Material", Html = "<b>Third Material Content</b>", DirectoryId = context.Directory.Last().Id }); context.SaveChanges(); } }
public static string AddUpdateContact(ContactInfo Info) { try { var ExistingContact = db.ContactInfo.Where(x => x.ID == Info.ID).FirstOrDefault(); if (ExistingContact == null) { db.ContactInfo.Add(Info); db.SaveChanges(); return("1"); } else { ExistingContact.firstName = Info.firstName; ExistingContact.lastName = Info.lastName; ExistingContact.Email = Info.Email; ExistingContact.PhoneNumber = Info.PhoneNumber; ExistingContact.isActive = Info.isActive; db.Entry(ExistingContact).State = EntityState.Modified; db.SaveChanges(); return("2"); } } catch (Exception ex) { Logging.Logging.WriteErrorLog(ex); return("0"); } }
public IActionResult AddUser(UserEditor model) { var team = _context.Teams.Include(t => t.Project).SingleOrDefault(t => t.Name == model.SelectedTeam); if (model.UserId == null) { var newUser = new User { Name = model.UserName, Team = team, Project = team?.Project, Course = model.UserCourse, Group = model.UserGroup }; _context.Users.Add(newUser); } else { var userToUpdate = _context.Users.Find(model.UserId); userToUpdate.Name = model.UserName; userToUpdate.Team = team; userToUpdate.Project = team?.Project; userToUpdate.Course = model.UserCourse; userToUpdate.Group = model.UserGroup; _context.Update(userToUpdate); } _context.SaveChanges(); return(RedirectToAction("AllUsers", "Users")); }
public IActionResult AddTeam(TeamEditor model) { var project = _context.Projects.SingleOrDefault(p => p.Name == model.SelectedProject); if (model.TeamId == null) { var newTeam = new Team { Name = model.TeamName, Project = project }; _context.Teams.Add(newTeam); } else { var teamToUpdate = _context.Teams .Include(t => t.Project) .Include(t => t.Members) .SingleOrDefault(u => u.Id == model.TeamId); foreach (var student in teamToUpdate.Members) { student.Project = project; } teamToUpdate.Name = model.TeamName; teamToUpdate.Project = project; _context.Update(teamToUpdate); } _context.SaveChanges(); return(RedirectToAction("AllTeams", "Teams")); }
public void Create(Book book) { if (book == null) { return; } _context.Entry(book).State = EntityState.Added; book.Authors.ForEach(author => { if (author.AuthorId != 0) { _context.Entry(author).State = EntityState.Modified; } }); book.Genres.ForEach(genre => { if (genre.GenreId != 0) { _context.Entry(genre).State = EntityState.Modified; } }); _context.SaveChanges(); }
public IActionResult AddFile(FileViewModel fileViewModel) { Docs document = new Docs() { Annotation = fileViewModel.Annotation }; if (fileViewModel.FileDocument != null && (fileViewModel.FileDocument.FileName.Contains("docx") || fileViewModel.FileDocument.FileName.Contains("xlsx"))) { byte[] docData = null; using (var binaryReader = new BinaryReader(fileViewModel.FileDocument.OpenReadStream())) { docData = binaryReader.ReadBytes((int)fileViewModel.FileDocument.Length); } document.FileDocument = docData; document.Name = fileViewModel.FileDocument.FileName; if (fileViewModel.MasterGuid != Guid.Empty) { document.ParentId = fileViewModel.MasterGuid; } _context.Docs.Add(document); _context.SaveChanges(); } return(RedirectToAction("Index")); }
public long AddMessage(long profileIdFrom, long profileIdTo, string message, DateTime dT) { var newMessage = new Message { ProfileIdFrom = profileIdFrom, ProfileIdTo = profileIdTo, MessageText = message, DT = dT }; context.Messages.Add(newMessage); var messageLast = MessagesLast.Where(m => m.ProfileIdTo == profileIdTo && m.ProfileIdFrom == profileIdFrom) .FirstOrDefault(); if (messageLast != null) { messageLast.DT = dT; } else { messageLast = new MessageLast { ProfileIdTo = profileIdTo, ProfileIdFrom = profileIdFrom, DT = dT }; context.MessagesLast.Add(messageLast); } context.SaveChanges(); return(newMessage.MessageId); }
public override Task <DeleteEmployeeResult> DeleteEmployee(EmployeeRequest request, ServerCallContext context) { var employee = _db.Employees.FirstOrDefault(emp => emp.Id == request.Id); _db.Employees.Remove(employee); _db.SaveChanges(); return(Task.FromResult(new DeleteEmployeeResult { Success = true })); }
public IActionResult AddProject(ProjectEditor model) { var teams = new List <Team>(); model.SelectedTeams?.ForEach(t => teams.Add(_context.Teams.Include(p => p.Project).Include(u => u.Members).SingleOrDefault(i => i.Name == t))); var members = new List <User>(); foreach (var team in teams) { foreach (var student in team.Members) { members.Add(student); } } if (model.ProjectId == null) { var newProject = new Project { Name = model.ProjectName, ShortDescription = model.ShortDescription, Teams = teams, Theme = model.Theme, GoalDescription = model.GoalDescription, ProblemDescription = model.ProblemDescription, RolesDescription = model.RolesDescription, ResultDescription = model.ResultDescription, Curator = model.Curator, CustomerOrganization = model.CustomerOrganization, CustomerContacts = model.CustomerContacts, Participants = members }; _context.Projects.Add(newProject); _context.SaveChanges(); return(RedirectToAction("AllProjects", "Projects")); } else { var projectToUpdate = _context.Projects.Include(p => p.Teams).SingleOrDefault(p => p.Id == model.ProjectId); projectToUpdate.Name = model.ProjectName; projectToUpdate.ShortDescription = model.ShortDescription; projectToUpdate.Teams = teams; projectToUpdate.Theme = model.Theme; projectToUpdate.GoalDescription = model.GoalDescription; projectToUpdate.ProblemDescription = model.ProblemDescription; projectToUpdate.RolesDescription = model.RolesDescription; projectToUpdate.ResultDescription = model.ResultDescription; projectToUpdate.Curator = model.Curator; projectToUpdate.CustomerOrganization = model.CustomerOrganization; projectToUpdate.CustomerContacts = model.CustomerContacts; projectToUpdate.Participants = members; _context.Update(projectToUpdate); _context.SaveChanges(); return(RedirectToAction("ProjectPage", "Projects", new { id = model.ProjectId })); } }
public ActionResult Create([Bind(Include = "CategoryID,CategoryName")] Category category) { if (ModelState.IsValid) { db.Category.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public IActionResult TopUpBalance(UserInfoViewModel model) { //Находим в бд текущего пользователя var users = _dataContext.Users.Include(x => x.Wallet).ToList(); User currentUser = users.FirstOrDefault(p => p.UserName == User.Identity.Name); //Пополняем кошелек currentUser.Wallet.TotalSum += model.AddedSum; _dataContext.SaveChanges(); return(View()); }
public void CreateItem(T item) { _dbSet.Add(item); try { context.SaveChanges(); } catch (Exception e) { } }
public void DeleteBook(Book book) { if (book != null) { /*context.Entry(book).State = EntityState.Deleted; * context.SaveChanges();*/ context.book.Remove(book); context.SaveChanges(); } //AdoNetTools.DeleteBook(Id); }
public ActionResult Create([Bind(Include = "ID,Name,Email,Address,Phone,Urgent")] Client client) { if (ModelState.IsValid) { db.Clients.Add(client); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(client)); }
public ActionResult PurchaseItem(int[] ItemId, decimal[] Quantiy, int[] Company, int[] Color, decimal[] UnitPrice, decimal[] Total_Price, string PurchaseDate) { for (int i = 0; i < ItemId.Length; i++) { if (Color[i] == 0) { Color[i] = 6; } int col = Color[i]; int com = Company[i]; int item = ItemId[i]; int existance = contex.Stocks.Where(m => m.ProductId == item).Where(m => m.ColorId == col).Where(m => m.CompanyId == com).Select(n => n.StockId).FirstOrDefault(); if (existance == 0) { Purchase p = new Purchase(); p.PurchaseDate = Convert.ToDateTime(PurchaseDate); p.ProductId = ItemId[i]; p.Quantity = Quantiy[i]; p.UnitPrice = UnitPrice[i]; p.CompanyId = Company[i]; p.ColorId = Color[i]; contex.Purchase.Add(p); contex.SaveChanges(); Stock st = new Stock(); st.ProductId = ItemId[i]; st.Quantity = Quantiy[i]; st.CompanyId = Company[i]; st.ColorId = Color[i]; contex.Stocks.Add(st); contex.SaveChanges(); } else { Stock s = contex.Stocks.Find(existance); //from stock in contex.Stocks where stock.StockId == existance select stock; //contex.Stocks.FirstOrDefault(m=>m.StockId==existance); s.Quantity += Quantiy[i]; contex.SaveChanges(); Purchase p = new Purchase(); p.PurchaseDate = Convert.ToDateTime(PurchaseDate); p.ProductId = ItemId[i]; p.Quantity = Quantiy[i]; p.UnitPrice = UnitPrice[i]; p.CompanyId = Company[i]; p.ColorId = Color[i]; contex.Purchase.Add(p); contex.SaveChanges(); } } return(View()); }
public void DeleteAuthor(Author author) { if (author != null) { /*context.Entry(book).State = EntityState.Deleted; * context.SaveChanges();*/ context.author.Remove(author); context.SaveChanges(); } //AdoNetTools.DeleteAuthor(id); }
public void SaveProduct(Product product) { if (product.Id == 0) { context.Products.Add(product); } else { context.Entry(product).State = EntityState.Modified; } context.SaveChanges(); }
public void SaveProject(Project project) { if (project.Id == 0) { context.Project.Add(project); } else { context.Entry(project).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public void SaveWorker(Worker worker) { if (worker.Id == 0) { context.Worker.Add(worker); } else { context.Entry(worker).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public void SaveDirectory(Directory directory) { if (directory.Id == 0) { context.Directories.Add(directory); } else { context.Entry(directory).State = EntityState.Modified; } context.SaveChanges(); }
public void SaveCategory(Category arhieve) { if (arhieve.Id == 0) { _context.Categories.Add(arhieve); } else { _context.Entry(arhieve).State = EntityState.Modified; } _context.SaveChanges(); }
public void SaveMaterial(Material material) { if (material.Id == 0) { context.Material.Add(material); } else { context.Entry(material).State = EntityState.Modified; } context.SaveChanges(); }
public void SaveDirectory(Directory directory) { if (directory.Id == 0) { context.Directory.Add(directory); } else { context.Entry(directory).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public void SaveBook(Content book) { if (book.Id == 0) { context.Books.Add(book); } else { context.Entry(book).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public void SaveMaterial(Material material) { if (material.Id == 0) { context.Material.Add(material); } else { context.Entry(material).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public ActionResult Create([Bind(Include = "SubCategoryID,SubCategoryName,CategoryID")] SubCategory subCategory) { if (ModelState.IsValid) { db.SubCategory.Add(subCategory); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Category, "CategoryID", "CategoryName", subCategory.CategoryID); return(View(subCategory)); }
public IActionResult DealSuccess(StockInfoViewModel model) { var users = _dataContext.Users.ToList(); User user = users.FirstOrDefault(p => p.UserName == User.Identity.Name); var wallets = _dataContext.Wallets.ToList(); Wallet wallet = wallets.FirstOrDefault(p => p.UserId == user.Id); int stockId = _currentStock.Id; var stocks = _dataContext.Stocks.ToList(); Stock stock = stocks.FirstOrDefault(p => p.Id == stockId); if (wallet.TotalSum >= model.StockNumber * _currentStock.CurrentPrice) { Deal deal = new Deal { DealDate = DateTime.Now, StockId = _currentStock.Id, Stock = stock, StockNumber = model.StockNumber, WalletId = wallet.Id, Wallet = wallet, CurrentStockPrice = _currentStock.CurrentPrice, IsBought = true }; _dataContext.Deals.Add(deal); wallet.TotalSum -= model.StockNumber * _currentStock.CurrentPrice; _dataContext.SaveChanges(); } return(View()); }
public void CommitPopRecords() { while (true) { try { using (var db = new EFDBContext()) { if (m_LastPopRecords == null) { return; } var records = m_LastPopRecords; db.DBItems.RemoveRange(records); db.SaveChanges(); m_LastPopRecords = null; return; } } catch (DbUpdateConcurrencyException) { _trace.Warn("DbUpdateConcurrencyException"); continue; } } }