public void Create(Pin pin, string userId)
 {
     pin.UserId = userId;
     pin.User = this.FindUser(userId);
     _repo.Add<Pin>(pin);
     _repo.SaveChanges();
     var boardId = pin.BoardId;
     this.UpdatePinCount(boardId);
 }
        public Pin PinIt(Pin pin, string userId, int boardId)
        {
            var newPin = new Pin
            {
                Title = pin.Title,
                BoardId = boardId,
                ImageUrl = pin.ImageUrl,
                Website = pin.Website,
                ShortDescription = pin.ShortDescription,
                LongDescription = pin.LongDescription,
                UserId = userId,
                User = this.FindUser(userId)
            };

            _repo.Add<Pin>(newPin);
            _repo.SaveChanges();
            this.UpdatePinCount(boardId);

            return newPin;
        }
        // POST: api/Pins
        public HttpResponseMessage Post(Pin pin)
        {
            var userId = this.User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                if (pin.Id == 0)
                {
                    _service.Create(pin, userId);

                    return Request.CreateResponse(HttpStatusCode.Created, pin);
                }
                else
                {
                    _service.Edit(pin.Id, pin);
                    return Request.CreateResponse(HttpStatusCode.OK, pin);
                }
            }
            return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
        }
        public void Edit(int id, Pin pin)
        {
            var original = this.FindPin(id);
            var originalBoardId = original.BoardId;
            original.BoardId = pin.BoardId;
            original.ImageUrl = pin.ImageUrl;
            original.LongDescription = pin.LongDescription;
            original.ShortDescription = pin.ShortDescription;
            original.Title = pin.Title;
            original.UserId = pin.UserId;
            original.User = pin.User;
            original.Website = pin.Website;

            _repo.SaveChanges();

            if (originalBoardId != pin.BoardId)
            {
                this.UpdatePinCount(originalBoardId);
                this.UpdatePinCount(pin.BoardId);
            }
        }