Esempio n. 1
0
        public async Task <IActionResult> Edit(HotSaleProducts hotsale)
        {
            var hotsales = _context.HotSaleProducts.Where(r => r.ID == hotsale.ID);

            if (hotsales.Any())
            {
                try
                {
                    var data = hotsales.FirstOrDefault();
                    data.ProductID       = hotsale.ProductID;
                    data.AdvertisingLine = hotsale.AdvertisingLine;
                    data.Url             = "/product/detail?id=" + hotsale.ProductID;
                    data.PublishDate     = hotsale.PublishDate;
                    data.DownDate        = hotsale.DownDate;
                    await _context.SaveChangesAsync();

                    return(Ok());
                }
                catch (Exception ex)
                {
                    return(StatusCode(Status400BadRequest, new ResponseMessage {
                        Message = ex.Message
                    }));
                }
            }
            else
            {
                return(StatusCode(Status400BadRequest, new ResponseMessage {
                    Message = "查無資訊"
                }));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(HotSaleProducts product)
        {
            try
            {
                product.Url = "/product/detail?id=" + product.ProductID;
                _context.HotSaleProducts.Add(product);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(Status400BadRequest, new ResponseMessage {
                    Message = ex.Message
                }));
            }
        }