public HttpResponseMessage SellMediaItem(SoldMediaDto soldMedia)
        {
            var mediaRepository = new MediaRepository();
            var getSingleItem   = mediaRepository.GetSingleItem(soldMedia.MediaId);

            soldMedia.MediaConditionId = getSingleItem.MediaConditionId;
            var soldMediaRepository = new SoldMediaRepository();
            var sellMedia           = soldMediaRepository.SellMedia(soldMedia);

            if (sellMedia)
            {
                return(Request.CreateResponse(HttpStatusCode.Created));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Could not sell Media item at this time, try again later"));
        }
Пример #2
0
        public bool SellMedia(SoldMediaDto soldMedia)
        {
            using (var db = CreateConnection())
            {
                db.Open();

                var sellMediaItem = db.Execute(@"INSERT INTO [dbo].[SoldMedia]
                                                       ([MediaId]
                                                       ,[Buyer]
                                                       ,[Amount]
                                                       ,[SoldDate]
                                                       ,[Notes]
                                                       ,[MediaConditionId])
                                                 VALUES
                                                       (@MediaId
                                                       ,@Buyer
                                                       ,@Amount
                                                       ,@SoldDate
                                                       ,@Notes
                                                       ,@MediaConditionId)", soldMedia);

                var markItemAsSold = 0;

                if (sellMediaItem == 1)
                {
                    markItemAsSold = db.Execute(@"UPDATE Media
                                                  SET IsSold = 1
                                                  WHERE Id = @id", new
                    {
                        id = soldMedia.MediaId
                    });
                }

                return(sellMediaItem == 1 && markItemAsSold == 1);
            }
        }