Example #1
0
        public async Task <IActionResult> ActivateUser(int UserId)
        {
            var user = _context.User.Find(UserId);

            if (user == null)
            {
                return(BadRequest("User Not Found!"));
            }

            user.Status = (int)Models.Enums.UserTypesStatus.Active;



            try
            {
                _context.Entry(user).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                BadRequest("Error!");
            }

            return(Ok(user));
        }
        public async Task <ActionResult> ChangeOfferStatus(int id, int status)
        {
            var offer = _context.OrderOffer.Find(id);
            var order = _context.Order.Find(offer.OrderId);

            if (offer == null)
            {
                return(BadRequest("Offer Not Found !"));
            }

            offer.Status = status; // Accepted
            try
            {
                _context.Entry(offer).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                switch (offer.Status)
                {
                case (int)Models.Enums.OfferStatus.Accepted:
                    notificationProvider.CreateNewNotification(order.UserId, offer.UserId, NotificationTemplates.AcceptOffer, "order-details/" + order.Id);
                    orderProcesses.CloseOrder(offer.OrderId, (int)Models.Enums.OrderStatus.Served);
                    break;

                case (int)Models.Enums.OfferStatus.Rejected:
                    notificationProvider.CreateNewNotification(order.UserId, offer.UserId, NotificationTemplates.RejectOffer, "order-details/" + order.Id);
                    break;
                }
            }
            catch (Exception e)
            {
                return(BadRequest("Error !"));
            }

            return(Ok(offer));
        }
Example #3
0
        public async Task <IActionResult> PutService(int id, Service service)
        {
            if (id != service.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> EditOrder(int id, Order order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #5
0
        public void CloseOrder(int orderId, int status)
        {
            var order = _context.Order.FirstOrDefault(x => x.Id == orderId);

            order.Status = status;

            try
            {
                _context.Entry(order).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                throw;
            }
        }