public IHttpActionResult PostChirp(Chirp chirp) { string username = User.Identity.Name; var user = db.Users.FirstOrDefault(u => u.UserName == username); if (user.Id == null) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else { chirp.UserId = user.Id; } chirp.CreatedDate = DateTime.Now; db.Chirps.Add(chirp); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = chirp.ChirpId }, chirp)); }
public IHttpActionResult PutChirp(int id, Chirp chirp) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != chirp.ChirpId) { return(BadRequest()); } db.Entry(chirp).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ChirpExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Process(MessageChirped messageChirped) { ChirperId chirpedBy = messageChirped.ChirpedBy; var myFollowers = _followersRepository.GetById(chirpedBy); if (myFollowers == null || !myFollowers.MyFollowers.Any()) return; var readers = myFollowers.MyFollowers.Select(f => f.Value).ToArray(); var chirper = _chirperRepository.GetById(chirpedBy); var chirpToAppend = new Chirp() { Id = messageChirped.ChirpId, ChirpedBy = chirper, Content = messageChirped.Content, ChirpedAt = messageChirped.ChirpedAt }; //ReadingStreams are created on sign-up so we can assume that they are there... foreach (var readingStream in readers.Select(readerId => _readingStreamRepository.GetById((ReaderId) readerId)).Where(readingStream => readingStream != null)) { readingStream.AppendToStream(chirpToAppend); _readingStreamRepository.Update(readingStream); } }
public IHttpActionResult PostChirp(Chirp chirp) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Get the username printed on the incoming token string username = User.Identity.Name; // Get the actual user from the database (may return null if not found!) ChirperUser user = db.Users.FirstOrDefault(u => u.UserName == username); if (user == null) { return(Unauthorized()); } chirp.UserId = user.Id; chirp.DateCreated = DateTime.Now; db.Chirps.Add(chirp); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = chirp.ChirpId }, chirp)); }
public void UpdateById(int id, Chirp updateChirp) { var chirpToUpdate = this.chirps.GetById(id); chirpToUpdate.Message = chirpToUpdate.Message; chirpToUpdate.Tags = chirpToUpdate.Tags; this.chirps.SaveChanges(); }
public IHttpActionResult GetChirp(int id) { Chirp chirp = db.Chirps.Find(id); if (chirp == null) { return(NotFound()); } return(Ok(chirp)); }
public void Process(MessageChirped messageChirped) { var chirper = _chirperEntityContext.GetById(messageChirped.ChirpedBy); var newChirp = new Chirp() { Id = messageChirped.ChirpId, ChirpedBy = chirper, Content = messageChirped.Content, ChirpedAt = messageChirped.ChirpedAt }; _chirpsEntityContext.Insert(newChirp); _chirpsEntityContext.Commit(); }
public IHttpActionResult PutChirp(int id, Chirp chirp) { var originalChirp = db.Chirps.Find(id); string username = User.Identity.Name; var user = db.Users.FirstOrDefault(u => u.UserName == username); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != chirp.ChirpId) { return(BadRequest()); } //if user has already like the Chirp do not increment LikeCount if (!originalChirp.LikedUsers.Contains(user)) { originalChirp.LikedUsers.Add(user); user.LikedChirps.Add(originalChirp); } if (chirp.Text != originalChirp.Text) { originalChirp.Text = chirp.Text; } db.Entry(originalChirp).State = EntityState.Modified; db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ChirpExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult DeleteChirp(int id) { Chirp chirp = db.Chirps.Find(id); if (chirp == null) { return(NotFound()); } db.Chirps.Remove(chirp); db.SaveChanges(); return(Ok(chirp)); }
public void AddChirpTest() { IChirpyRRepository repository = new ChirpyRSqlRepository("ChirpyRConnection", "dbo"); ChirpyRDataService target = new ChirpyRDataService(repository); Chirp newChirp = new Chirp { Text = "Test Chirp", ChirpTime = DateTime.Now, }; long notExpected = -1; long actual; actual = target.AddChirp(newChirp); Assert.AreNotEqual(notExpected, actual); }
// POST api/chirpyr public void Post(Chirp model) { if (ModelState.IsValid) { //_repository.AddChirp(model); var hubContext = GlobalHost .ConnectionManager .GetHubContext <ChirpyRHub>(); model.ChirpBy = new ChirpyRUser { UserId = this.User != null && this.User.Identity != null ? this.User.Identity.Name : "(none)", Gravataar = @"http://www.gravatar.com/avatar/147bacafcdb00d67d3336ecdf4078ba5.png" }; hubContext.Clients.NewChirp(model); } }
// POST api/chirpyr public void Post(Chirp model) { if (ModelState.IsValid) { //_repository.AddChirp(model); var hubContext = GlobalHost .ConnectionManager .GetHubContext <ChirpyRHub>(); var member = Membership.GetUser(); model.ChirpBy = new ChirpyRUser { UserId = this.User != null && this.User.Identity != null ? this.User.Identity.Name : "(none)", Gravataar = string.Format("http://www.gravatar.com/avatar/{0}?d=identicon", this.CreateMD5Hash(member.Email)) }; hubContext.Clients.NewChirp(model); } }
public IActionResult Post(DtoChirpPost dto) { _db.BeginTransaction(); var chirp = new Chirp { UserId = int.Parse(User.Identity.Name ?? "1"), ChirpTimeUtc = DateTime.UtcNow, ChirpType = ChirpType.Chirp, Contents = dto.Contents }; _db.Chirps.Add(chirp); _db.SaveChanges(); // Publish chirp processing job, before commit. // If the publishing fails, the transaction will be rolled back. // // We're using the job publish as the last committing resource because // it does not participate in the DB transaction. JobBatch.Do(() => { TimelineUpdate.Publish(new TimelineUpdateArgs { ChirpId = chirp.Id, AuthorId = chirp.UserId, TimeUtc = chirp.ChirpTimeUtc }); HashTagUpdate.Publish(chirp.Id); }); _db.CommitTransaction(); return(Ok(chirp.Id)); }
public void Create(Chirp chirp) { this.chirps.Add(chirp); this.chirps.SaveChanges(); }
public EngineManager(Chirp chirp) { this.chirp = chirp; }
public void DetachFromStream(Chirp chirp) { if (chirp != null && Content.Contains(chirp)) Content.Remove(chirp); }
public void AppendToStream(Chirp chirp) { if(chirp != null) Content.Add(chirp); }
public Bird() { Name = "Bird"; MoveBehaviour = new Fly(); MakeSoundBehaviour = new Chirp(); }