Ejemplo n.º 1
0
        public HttpResponseMessage Post([FromBody]AddFriendRequest data)
        {
            try
            {
                var logProfile = _logManager.ModelReader.GetLogProfile(data.LogProfileId);

                if (logProfile == null)
                    return Request.CreateErrorResponse(HttpStatusCode.Ambiguous, "profile not found");
                if (logProfile.Friends.Any(f => f.Email == data.Email))
                    return Request.CreateErrorResponse(HttpStatusCode.Ambiguous, "it's already a friend for this profile");

                var friend = new Friend
                    {
                        Email = data.Email,
                        LogProfiles = new List<LogProfile> {logProfile},
                        Active = true,
                        FriendActivities = new List<FriendActivity>
                            {
                                new FriendActivity
                                    {
                                        ActivityDate = DateTime.Now,
                                        Description = "Friend created",
                                    }
                            }
                    };

                _logManager.FriendCommands.Create(friend);
                _logManager.Save();
                return Request.CreateResponse(HttpStatusCode.Created, data);
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.GetBaseException().Message);
            }
        }
Ejemplo n.º 2
0
 public void Create(Friend item)
 {
     _db.Friends.Add(item);
 }