public bool PatchCount(ProductCountDto product)
        {
            using (var db = new SqlConnection(_connectionString))
            {
                var date = DateTime.Now;
                db.Open();
                var result = db.Execute(@"UPDATE [dbo].[Variants]
                                             SET [inventoryQuantity] = @inventoryQuantity
                                                ,[minimumStock] = @minimumStock
                                         WHERE Id = @Id", product);


                db.Execute(@"if exists (select variantId from Locations where variantId = @Id)
	                                update Locations
		                            set Name=@location, Available=@inventory_quantity, UpdatedAt=@date
		                            where variantId=@Id
                                else
	                                Insert Into dbo.Locations (name, available, updatedAt, variantId)
                                    values (@location
                                    ,@inventory_quantity
                                    ,@date
                                    ,@Id)", new { location = product.location, inventory_quantity = product.inventory_quantity, Id = product.Id, date });

                return(result == 1);
            }
        }
Example #2
0
        public HttpResponseMessage Patch(ProductCountDto details)
        {
            var repo   = new ProductsRepository();
            var update = repo.PatchCount(details);

            return(update
                ? Request.CreateResponse(HttpStatusCode.OK)
                : Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to process request"));
        }