public async Task <IActionResult> PutNotificationTbl([FromRoute] int id, [FromBody] NotificationTbl notificationTbl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            _context.Entry(notificationTbl).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NotificationTblExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostNotificationTbl([FromBody] NotificationTbl notificationTbl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.NotificationTbl.Add(notificationTbl);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetNotificationTbl", new { id = notificationTbl.Id }, notificationTbl));
        }
Beispiel #3
0
        public async Task <IActionResult> PostOrderTbl([FromBody] OrderTbl orderTbl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (orderTbl.PaymentType == "1")
            {
                orderTbl.PaymentType = "Cash On Delivery";
            }
            if (orderTbl.PaymentType == "2")
            {
                orderTbl.PaymentType = "Bkash";
            }
            orderTbl.OrderTime  = DateTime.Now;
            orderTbl.CustomerId = Global.UserID;

            //orderTbl.CustomerId = TempData["userid"] as string;
            _context.OrderTbl.Add(orderTbl);

            NotificationTbl notification = new NotificationTbl();

            notification.Message = "New Order placed by " + Global.UserName + " at " + orderTbl.OrderTime.Value.ToString("yyyy-MM-dd hh:mm:ss tt");
            Global.Counter++;
            _context.NotificationTbl.Add(notification);


            await _context.SaveChangesAsync();

            // return CreatedAtAction("GetOrderTbl", new { id = orderTbl.Id }, orderTbl);

            // signalR notification
            string retMessage;

            try
            {
                await _hubContext.Clients.All.BroadcastMessage(orderTbl.Id, orderTbl.Quantity, orderTbl.Subtotal, orderTbl.TotalPrice, orderTbl.PaymentType, orderTbl.CustomerId, orderTbl.MenueId, orderTbl.OrderTime);

                retMessage = "Success";
            }
            catch (Exception e)
            {
                retMessage = e.ToString();
            }
            // return retMessage;
            return(CreatedAtAction("GetOrderTbl", new { id = orderTbl.Id }, orderTbl));
        }