public async Task <EventViewModelReadOnly> GetById(string id) { var currentEvent = await db.Events.FindAsync(id).ConfigureAwait(false); EventViewModelReadOnly eventVM = new EventViewModelReadOnly { Name = currentEvent.Name, Logo = currentEvent.Logo, StartDate = currentEvent.StartDate, EndDate = currentEvent.EndDate, BuyTicket = currentEvent.BuyTicket.ToString(), CFP = new CallForSpeakerViewModel { Url = currentEvent.CFP.Url.ToString(), StartDate = currentEvent.CFP.StartDate, EndDate = currentEvent.CFP.EndDate } }; if (currentEvent?.Community != null) { var community = await db.Communities.FindAsync(currentEvent.Community.Name).ConfigureAwait(false); db.Entry(community).State = EntityState.Detached; eventVM.Community = new CommunityUpdateViewModel { Name = community.Name, Logo = community.Logo, WebSite = community.WebSite.ToString() }; } return(eventVM); }
public ActionResult EditDisplay([Bind(Include = "ID,UserName,Location,Email")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Display")); } return(View(user)); }
public bool Delete(int ID) { var _event = eventcontext.EventLogs.Where(x => x.EventID == ID).FirstOrDefault(); if (_event != null) { eventcontext.Entry(_event).State = EntityState.Deleted; eventcontext.SaveChanges(); return(true); } return(false); }
public ActionResult Edit([Bind(Include = "Id,NameEvent,Address,Description,DateEvent,TimeEvent")] Event eventEdit) { if (ModelState.IsValid) { db.Entry(eventEdit).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(eventEdit)); }
public async Task <IActionResult> PutCategory(int id, Category category) { if (id != category.CategoryId) { return(BadRequest()); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task<IActionResult> PutCity([FromRoute] int id, [FromBody] City city) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != city.Id) { return BadRequest(); } _context.Entry(city).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CityExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public async Task <ActionResult <Event> > PutEvent(int id, Event @event) { if (id != @event.EventId) { return(BadRequest()); } _context.Entry(@event).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventExists(id)) { return(NotFound()); } else { throw; } } @event.Category = _context.Category.Find(@event.CategoryId); return(@event); }
public async Task <IActionResult> PutRole(int id, Role role) { if (id != role.Id) { return(BadRequest()); } _context.Entry(role).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutEvent(Guid id, Event @event) { if (id != @event.Id) { return(BadRequest()); } _context.Entry(@event).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutEvent(int id, Event @event) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != @event.Id) { return(BadRequest()); } db.Entry(@event).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EventExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutOrderDetail([FromRoute] int id, [FromBody] OrderDetail orderDetail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != orderDetail.Id) { return(BadRequest()); } _context.Entry(orderDetail).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderDetailExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUser(int id, User user) { if (id != user.UserId) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult MessageDetails(int id) { Message message = db.Message.Find(id); if (message == null || (message.FromUser != User.Identity.Name && message.ToUser != User.Identity.Name)) { return(HttpNotFound()); } if (message.IsRead == false) { message.IsRead = true; db.Entry(message).State = EntityState.Modified; db.SaveChanges(); } return(View(message)); }
public bool Save(User user) { User u = context.Users.Where(x => x.Email == user.Email).FirstOrDefault(); if (u != null) { throw new EmailAlreadyExistsException("Email já está em uso"); } // Encrypts user password user.Password = Md5Hash.Generate(user.Password); var state = user.Id == 0 ? EntityState.Added : EntityState.Modified; context.Entry(user).State = state; context.Add(user); context.SaveChanges(); return(true); }
public ActionResult Edit([Bind(Include = "ParticipantID,FirstName,LastName,Major")] Participant participant) { if (ModelState.IsValid) { db.Entry(participant).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(participant)); }
public ActionResult Edit([Bind(Include = "StaffID,StaffCode,StaffName,TeamStaff")] Staff staff) { if (ModelState.IsValid) { db.Entry(staff).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(staff)); }
public ActionResult Edit([Bind(Include = "TournamentID,TournamentName,EventID,Description,Game,ApiId,UrlString,IsTeams")] Tournament tournament) { if (ModelState.IsValid) { db.Entry(tournament).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(tournament); }
public ActionResult Edit([Bind(Include = "ID,UserID,Event,Date")] Events events) { if (ModelState.IsValid) { db.Entry(events).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(events)); }
public ActionResult Edit([Bind(Include = "EventID,Subject,Description,Partcipant,Start,End,ThemeColor")] Event @event) { if (ModelState.IsValid) { db.Entry(@event).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(@event)); }
public ActionResult Edit([Bind(Include = "ID,NAME,DESCRIPTION,COUNTRY,STATE,CITY,STREETADDRESS,ZIPCODE,STARTDATE,STARTTIME,ENDDATE,ENDTIME")] Event @event) { if (ModelState.IsValid) { db.Entry(@event).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(@event)); }
public ActionResult Edit([Bind(Include = "EventId,EventName,Date,Location,Guests,Description")] Event @event) { if (ModelState.IsValid) { db.Entry(@event).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(@event)); }
public ActionResult Edit([Bind(Include = "EventID, EventName,Venue,Address,Date,Time")] Events events) { if (ModelState.IsValid) { db.Entry(events).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(events)); }
public ActionResult Edit([Bind(Include = "EventID,EventName,Description,Country,City,EventStart,EventEnd,TotalPitStops,TotalTeams")] Event @event) { if (ModelState.IsValid) { db.Entry(@event).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(@event)); }
public async Task ProcessAsync() { using (var db = new EventContext()) { await db.Database.EnsureDeletedAsync(); await db.Database.EnsureCreatedAsync(); var speakers = Data.CreateSpeakers(10).ToList(); await db.Speakers.AddRangeAsync(speakers); await db.SaveChangesAsync(); using (new Measure()) { await db.Sessions.AddRangeAsync(Data.CreateSessions(speakers, 1000)); await db.SaveChangesAsync(); } } var factory = new LoggerFactory(); factory.AddConsole(LogLevel.Information); var builder = new DbContextOptionsBuilder <EventContext>(); builder.UseSqlServer("Data Source=.;Initial Catalog=AdcSample; Integrated Security=True;") .UseLoggerFactory(factory); using (var db = new EventContext(builder.Options)) { await db.Speakers.CountAsync(); using (new Measure()) { var data = await db.Speakers.Include(p => p.Sessions).ToListAsync(); Console.WriteLine($"got {data.Count} speaker"); var s = data.First(); db.Entry(s) .Property("IsDeleted").CurrentValue = true; await db.SaveChangesAsync(); } } using (var db = new EventContext(builder.Options)) { var count = await db.Speakers.CountAsync(); Console.WriteLine($"SpeakerCount {count}"); } }
public ActionResult UpdateUser([Bind(Include = "UserID, Password, FirstName, LastName," + "DateOfBirth, Gender, Role, ImageFile, MajorID, IsInActive")] UserViewModel usr) { if (!string.IsNullOrEmpty(usr.UserID) || !string.IsNullOrEmpty(usr.FirstName) || !string.IsNullOrEmpty(usr.LastName)) { User updateusr = new User(); if (usr.ImageFile != null) { string relativePath = "~/Images/" + DateTime.Now.Ticks.ToString() + "_" + usr.ImageFile.FileName; string physicalPath = Server.MapPath(relativePath); string imageFolder = Path.GetDirectoryName(physicalPath); if (!Directory.Exists(imageFolder)) { Directory.CreateDirectory(imageFolder); } usr.ImageFile.SaveAs(physicalPath); usr.ImageURL = relativePath; } else { var curUsr = (from x in db.Users where x.id == usr.UserID select x.imageUrl).FirstOrDefault(); usr.ImageURL = curUsr; } if (usr.Password == null) { var curUsr = (from x in db.Users where x.id == usr.UserID select x.password).FirstOrDefault(); usr.Password = getMD5(curUsr); } usr.updateUser(updateusr); db.Entry(updateusr).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("UsersList")); } return(View()); }
public ActionResult Edit([Bind(Include = "TeamID,TeamName,EventID")] Team team) { if (ModelState.IsValid) { db.Entry(team).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", team.EventID); return(View(team)); }
public ActionResult Edit([Bind(Include = "MemberID,MemberName,TeamID,ContactNo,Email")] Member member) { if (ModelState.IsValid) { db.Entry(member).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", member.TeamID); return(View(member)); }
public ActionResult Edit(Event mEvent) { if (ModelState.IsValid) { db.Entry(mEvent).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Category, "CategoryId", "Name", mEvent.CategoryId); return(View(mEvent)); }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "PitStopID,EventID,StopName,StopOrder,Location,StaffID")] PitStop pitStop) { if (ModelState.IsValid) { db.Entry(pitStop).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", pitStop.EventID); ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffCode", pitStop.StaffID); return(View(pitStop)); }