public SuccessfullOperated<FriendshipResponseModel> RequestFriendship(FriendshipResponseModel model) { var successfullOperated = new SuccessfullOperated<FriendshipResponseModel>() { IsSuccessfull = false, Element = model }; var firstUser = this.data.Users .All() .FirstOrDefault(f => f.Id == model.FirstUserId); if (firstUser == null) { return successfullOperated; } var secondUser = this.data.Users .All() .FirstOrDefault(f => f.Id == model.SecondUserId); if (secondUser == null) { return successfullOperated; } var friendshipForDb = new Friendship() { FirstUserId = model.FirstUserId, FirstUser = firstUser, SecondUserId = model.SecondUserId, SecondUser = secondUser, IsApproved = false, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsDeleted = false, IsFirstUserSender = true }; try { this.data.Friendships.Add(friendshipForDb); this.data.SaveChanges(); successfullOperated.IsSuccessfull = true; return successfullOperated; } catch (Exception) { return successfullOperated; } }
public IHttpActionResult RequestFriendship(FriendshipResponseModel model) { IHttpActionResult updateMessage; if (CheckModelState(out updateMessage)) { return updateMessage; } var result = this.profileServices.RequestFriendship(model); if (!result.IsSuccessfull) { return this.BadRequest(); } return this.Ok(result.Element); }
public IHttpActionResult Update(int id, FriendshipResponseModel model) { IHttpActionResult updateMessage; if (CheckModelState(out updateMessage)) { return updateMessage; } var result = this.friendshipsServices.Update(id, model); if (!result.IsSuccessfull) { return this.BadRequest(); } return this.Ok(result.Element); }
public SuccessfullOperated<FriendshipResponseModel> Update(int id, FriendshipResponseModel model) { var successfullOperated = new SuccessfullOperated<FriendshipResponseModel>() { IsSuccessfull = false, Element = model }; var modelFromDb = this.data.Friendships .All() .FirstOrDefault(m => m.Id == id); if (modelFromDb == null) { return successfullOperated; } if (!string.IsNullOrEmpty(model.FirstUserId)) { modelFromDb.FirstUserId = model.FirstUserId; } if (!string.IsNullOrEmpty(model.SecondUserId)) { modelFromDb.SecondUserId = model.SecondUserId; } modelFromDb.IsApproved = model.IsApproved; data.SaveChanges(); successfullOperated.IsSuccessfull = true; return successfullOperated; }