public async Task <IActionResult> PutRideMetric(int id, RideMetric rideMetric) { if (id != rideMetric.Id) { return(BadRequest()); } _context.Entry(rideMetric).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RideMetricExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutComment([FromRoute] int id, [FromBody] Comment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != comment.Id) { return(BadRequest()); } _context.Entry(comment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutPublisher(int id, Publisher publisher) { if (id != publisher.PubId) { return(BadRequest()); } _context.Entry(publisher).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PublisherExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> CreateContractAsync([FromBody] Contracts contract) { if (contract == null) { return(BadRequest("")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var entry = _context.Add(new Contracts()); entry.CurrentValues.SetValues(contract); await _context.SaveChangesAsync(); } catch (Exception ex) { var logdetails = new EventLog() { ContractId = contract.ContractId, LogMessage = ex.Message, VersionUser = "******", VersionDate = DateTime.Now }; var errorlog = _context.Add(new EventLog()); errorlog.CurrentValues.SetValues(logdetails); await _context.SaveChangesAsync(); } return(CreatedAtRoute("GetContract", contract)); }
public async Task <IActionResult> PutPersonas3(int id, [FromBody] Personas3 personas3) { if (id != personas3.Id) { return(BadRequest()); } _context.Entry(personas3).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Personas3Exists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUsuarios2(int id, [FromBody] Usuarios2 usuarios2) { if (id != usuarios2.Id) { return(BadRequest()); } _context.Entry(usuarios2).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Usuarios2Exists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult GetAllContracts() { var item = _context.Contracts.Select(t => t.Status == "Approved"); try { if (item == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } } catch (Exception ex) { var logdetails = new EventLog() { ContractId = 0, LogMessage = ex.Message, VersionUser = "******", VersionDate = DateTime.Now }; var errorlog = _context.Add(new EventLog()); errorlog.CurrentValues.SetValues(logdetails); _context.SaveChangesAsync(); } return(new ObjectResult(item)); }
public async Task <IActionResult> Create([Bind("Enum,Fname,Mname,Lname,Hours,Email")] Models.Entities.Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("UserId,Useremail,UserPassword,UserType,UserStatus")] Gauser gauser) { if (ModelState.IsValid) { _context.Add(gauser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(gauser)); }
public async Task <IActionResult> Create([Bind("IdStudy,Name")] Studies studies) { if (ModelState.IsValid) { _context.Add(studies); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(studies)); }
public async Task <IActionResult> Create([Bind("Semester,IdStudy,StartDate,IdEnrollment")] Enrollment enrollment) { if (ModelState.IsValid) { _context.Add(enrollment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdStudy"] = new SelectList(_context.Studies, "IdStudy", "Name", enrollment.IdStudy); return(View(enrollment)); }
public async Task <IActionResult> Create([Bind("BlogUserName,BlogUserPassword,BlogUserAge")] Users users) { if (ModelState.IsValid) { users.BlogIsAdmin = false; _context.Add(users); await _context.SaveChangesAsync(); return(await Login(users)); } return(View(users)); }
public async Task <int> AddReminder(Reminder reminder) { if (db != null) { await db.Reminder.AddAsync(reminder); await db.SaveChangesAsync(); return(reminder.ReminderId); } return(0); }
public async Task <IActionResult> Create([Bind("FolderNum,ApplicationDate,Enum,ConcentrationId,JobId")] Application application) { if (ModelState.IsValid) { _context.Add(application); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ConcentrationId"] = new SelectList(_context.Concentration, "ConcentrationId", "ConcentrationId", application.ConcentrationId); ViewData["Enum"] = new SelectList(_context.Student, "Enum", "Enum", application.Enum); ViewData["JobId"] = new SelectList(_context.Job, "JobId", "JobId", application.JobId); return(View(application)); }
public async Task <IActionResult> Create([Bind("PostId,Author,Content,Date")] Comments comments) { comments.Author = comments.Author == null ? "Anon" : comments.Author; comments.Date = DateTime.Now; if (CommentsExists(comments.Id)) { var z = _context.Comments.Select((x) => x.Id).OrderByDescending((y) => y).ToList(); comments.Id = z[0] + 1; } _context.Add(comments); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("IndexNumber,FirstName,LastName,BirthDate,IdEnrollment")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdEnrollment"] = new SelectList(_context.Enrollment, "IdEnrollment", "IdEnrollment", student.IdEnrollment); return(View(student)); }
public async Task <IActionResult> Create([Bind("Title,Date,Content")] Posts posts) { int z = !_context.Posts.Any() ? 1 : _context.Posts.Max(x => x.Id); posts.Id = z + 1; if (!HttpContext.Session.TryGetValue("UserName", out var userName)) { return(RedirectToAction("Login", "Users")); } posts.Author = System.Text.Encoding.UTF8.GetString(userName); _context.Add(posts); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult <Pets> > Post([FromBody] Pets value) { using (masterContext context = new masterContext()) { var newPet = await context.Pets.AddAsync(value); await context.SaveChangesAsync(); return(newPet.Entity); } }
public async Task <IActionResult> Create([Bind("Title,Time,Long,Lat")] Events events) { int z = !_context.Events.Any() ? 1 : _context.Events.Max(x => x.Id); events.Id = z + 1; if (!HttpContext.Session.TryGetValue("UserName", out var userName)) { return(RedirectToAction("Users", "Login")); } events.Author = System.Text.Encoding.UTF8.GetString(userName); if (ModelState.IsValid) { _context.Add(events); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(events)); }
public async Task <ActionResult <AnimalType> > Post([FromBody] AnimalType value) { using (masterContext context = new masterContext()) { var newType = await context.AnimalType.AddAsync(value); await context.SaveChangesAsync(); return(newType.Entity); } }
public async Task <ActionResult <AnimalType> > UpdateType(int id, [FromBody] AnimalType value) { using (masterContext context = new masterContext()) { AnimalType animalType = await context.AnimalType.Where(p => p.TypeId == id).FirstOrDefaultAsync(); animalType.TypeName = value.TypeName; var editedType = context.AnimalType.Update(animalType); await context.SaveChangesAsync(); return(editedType.Entity); } }
public async Task <IActionResult> PutArticle([FromRoute] int id, [FromBody] Article article) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Article tempArticle = await _context.Article.FindAsync(id); tempArticle.Id = id; tempArticle.Title = article.Title; tempArticle.ContentMain = article.ContentMain; tempArticle.ContentSummary = article.ContentSummary; tempArticle.CategoryId = article.Category.Id; tempArticle.Picture = article.Picture; _context.Entry(tempArticle).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Pets> > UpdatePet(int id, [FromBody] Pets value) { using (masterContext context = new masterContext()) { Pets pet = await context.Pets.Where(p => p.PetId == id).FirstOrDefaultAsync(); pet.OwnerId = value.OwnerId; pet.TypeId = value.TypeId; pet.PetName = value.PetName; var editedPet = context.Pets.Update(pet); await context.SaveChangesAsync(); return(editedPet.Entity); } }