예제 #1
0
        public async Task <bool> PutStore(Store store)
        {
            try
            {
                _context.Entry(store).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                var result = _context.WorkHours.Where(w => w.StoreId == store.StoreId).ToList();

                _context.WorkHours.RemoveRange(result);

                await _context.SaveChangesAsync();

                _context.WorkHours.AddRange(store.WorkHours);

                await _context.SaveChangesAsync();


                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StoreExists(store.StoreId))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
예제 #2
0
        public async Task <IActionResult> PutEmployeeWorkHour(Guid id, EmployeeWorkHour employeeWorkHour)
        {
            if (id != employeeWorkHour.WorkHourId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> PutStoreLicense(Guid id, StoreLicense storeLicense)
        {
            if (id != storeLicense.LicenseId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #4
0
        public async Task <IActionResult> PutPaymentCard(Guid id, PaymentCard paymentCard)
        {
            if (id != paymentCard.PaymentCardId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #5
0
        public async Task <IActionResult> PutSubcription(string id, Subcription subcription)
        {
            if (id != subcription.StripeSubCriptionID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #6
0
        public async Task <ActionResult <bool> > PutOrder(Order orderupdated)
        {
            _context.Entry(orderupdated).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();



                if (orderupdated.OrderStatus == Status.Submited)
                {
                    foreach (var item in orderupdated.OrderProducts)
                    {
                        var product = _context.Products.Where(p => p.StoreId == item.StoreId && p.ProductId == item.ProductIdReference).FirstOrDefault();

                        if (product != null && product.InventoryQuantity > 0)
                        {
                            product.InventoryQuantity -= item.Quantity;

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

                            await _context.SaveChangesAsync();
                        }
                    }
                }

                //_context.SaveChanges();

                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(orderupdated.OrderId))
                {
                    return(NotFound());
                }
                else
                {
                    return(false);
                }
            }
        }
예제 #7
0
        public async Task <ActionResult <bool> > ValidateEmail(string code, string userid)
        {
            var validate = await _context.EmailValidations.Where(email => email.ValidationCode == code && email.UserId.ToString() == userid && DateTime.Now <= email.ExpDate).FirstOrDefaultAsync();


            if (validate != null)
            {
                var user = await _context.Users.Where(u => u.UserId.ToString() == userid).FirstOrDefaultAsync();

                user.IsValidUser = true;

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

                await _context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
        public async Task <bool> PutStoreLicense(StoreLicense storeLicense)
        {
            _context.Entry(storeLicense).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StoreLicenseExists(storeLicense.LicenseId))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
예제 #9
0
        public async Task <ActionResult <bool> > ModifyOldConnections(UsersConnected usersConnected)
        {
            var userconnections = await _context.usersConnecteds.Where(usc => usc.UserID == usersConnected.UserID && usc.IsDisable == false).ToListAsync();


            if (userconnections.Count() > 0)
            {
                foreach (var item in userconnections)
                {
                    item.IsDisable = true;

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

                    _context.SaveChanges();
                }


                return(true);
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task <bool> PutWorkHour(WorkHour workHour)
        {
            _context.Entry(workHour).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkHourExists(workHour.WorkHourId))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
        public async Task <bool> UpdateInventoryItem(Guid productId, int quantity)
        {
            var product = await _context.Products.Where(p => p.ProductId == productId).FirstOrDefaultAsync();

            product.InventoryQuantity -= quantity;

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


            try
            {
                _context.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                return(false);
            }
        }