コード例 #1
0
        public IHttpActionResult PostFriends(Friends friends)
        {
            var temp = new Friends();
            temp = db.Friends.Where(c => 
                (c.UserId == friends.UserId && c.FriendId == friends.FriendId) 
                || (c.UserId == friends.FriendId && c.FriendId == friends.UserId)).SingleOrDefault();

            if (temp != null)
            {
                return BadRequest("Friendship already exist");
            }

            friends.Status = FriendStatus.Friend;
            friends.ActionDate = DateTime.Now;
            
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            friends.User = db.Users.Where(c => c.Id == friends.UserId).SingleOrDefault();
            friends.Friend = db.Users.Where(c => c.Id == friends.FriendId).SingleOrDefault();

            db.Friends.Add(friends);
            db.SaveChanges();

            return Ok("Friendship created");
        }
コード例 #2
0
        public IHttpActionResult PutFriends(int id, Friends friends)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != friends.Id)
            {
                return BadRequest();
            }

            db.Entry(friends).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FriendsExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #3
0
ファイル: ModelFactory.cs プロジェクト: jcarroll2007/Faces
        public static FriendModel ParseFriendRequestEntityToModel(Friends entity)
        {
            var model = new FriendModel();
            model.Status = entity.Status;
            model.ActionDate = entity.ActionDate;
            model.Id = entity.UserId;
            model.FirstName = entity.User.FirstName;
            model.LastName = entity.User.LastName;
            model.ProfilePicture = entity.User.ProfilePicture;
            model.Phone = entity.User.Phone;
            model.DateOfBirth = entity.User.DateOfBirth.HasValue ? entity.User.DateOfBirth.Value.ToShortDateString() : null;
            model.Email = entity.User.Email;
            model.City = entity.User.City;
            model.AboutMe = entity.User.AboutMe;
            model.Gender = entity.User.Gender;
            model.State = entity.User.State;


            return model;
        }
コード例 #4
0
ファイル: ModelFactory.cs プロジェクト: jcarroll2007/Faces
        public static Friends ParseFriendModelToEntiy(FriendModel model)
        {
            var entity = new Friends();
            entity.Status = model.Status;
            entity.ActionDate = model.ActionDate;
            entity.Id = model.Id;
            entity.Friend.FirstName = model.FirstName;
            entity.Friend.LastName = model.LastName;
            entity.Friend.ProfilePicture = model.ProfilePicture;
            entity.Friend.Phone = model.Phone;
            if (!String.IsNullOrEmpty(model.DateOfBirth))
            {
                entity.Friend.DateOfBirth = Convert.ToDateTime(model.DateOfBirth);
            }
            entity.Friend.Email = model.Email;
            entity.Friend.City = model.City;
            entity.Friend.AboutMe = model.AboutMe;
            entity.Friend.Gender = model.Gender;
            entity.Friend.State = model.State;

            return entity;
        }