public virtual async Task <T> Create(T obj) { _context.Add(obj); await _context.SaveChangesAsync(); return(obj); }
public async Task <IActionResult> Create([Bind("Information,IsCommercial")] Address address) { if (ModelState.IsValid) { try { _context.Add(address); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException ex) { if (ex.HResult == -2146233088) { ModelState.AddModelError("", @"Unable to save changes. Address already exists"); } else { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } } } return(View(address)); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,Creator,CreationDate")] Topic topic) { if (ModelState.IsValid) { var claimsIdentity = User.Identity as ClaimsIdentity; if (claimsIdentity != null) { var userIdClaim = claimsIdentity.Claims .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier); if (userIdClaim != null) { var userIdValue = userIdClaim.Value; topic.Creator = userIdValue; } } topic.Id = Guid.NewGuid(); _context.Add(topic); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Creator"] = new SelectList(_context.Users, "Id", "Id", topic.Creator); return(View(topic)); }
public async Task <IActionResult> Create([Bind("Name,Description,UserID")] Department department) { if (ModelState.IsValid) { try { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException ex) { if (ex.HResult == -2146233088) { ModelState.AddModelError("", @"Unable to save changes. Department already exists"); } else { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } } } ViewData["UserID"] = new SelectList(_context.User, "ID", "Name", department.UserID); return(View(department)); }
public async Task <IActionResult> AddOrEdit([Bind("ManagerNotesId,Title,TextOfNote")] ManagerNote managerNote) { if (ModelState.IsValid) { if (managerNote.ManagerNotesId == 0) { _context.Add(managerNote); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { _context.Update(managerNote); await _context.SaveChangesAsync(); return(RedirectToRoute(new { controller = "ManagerNote", action = "Index", titleOfNote = managerNote.Title })); } } return(View(managerNote)); }
public async Task <IActionResult> Create( [Bind("Name,Age,Email,Description")] User user) { try { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException ex) { if (ex.HResult == -2146233088) { ModelState.AddModelError("", @"Unable to save changes. User already exists"); } else { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } } return(View(user)); }
public async Task <IActionResult> Create([Bind("Id,ProjectName,NumberOfWorkers")] Proekt proekt) { if (ModelState.IsValid) { _context.Add(proekt); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(proekt)); }
public async Task <IActionResult> Create([Bind("ManagerID,FirstName,LastName,Department")] Manager manager) { if (ModelState.IsValid) { _context.Add(manager); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(manager)); }
public async Task <IActionResult> Create([Bind("Name,Surname,Email")] Programist programist) { try { if (ModelState.IsValid) { _context.Add(programist); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(programist)); }