Exemplo n.º 1
0
        public async Task <bool> AddUsers(UserTable user)
        {
            try
            {
                if (user.CompanyId.HasValue)
                {
                    user.CompanyLocalId = _context.Company.FirstOrDefaultAsync(company => company.Id == user.CompanyId).Result.LocalId;
                }
                _context.UserTable.Add(user);
                var response = await _context.SaveChangesAsync();

                if (response >= 1)
                {
                    var userCart = new UserCartMapping()
                    {
                        Id          = Guid.NewGuid(),
                        UserId      = user.Id,
                        UserLocalId = user.LocalId
                    };
                    _context.UserCartMapping.Add(userCart);
                }
                var response1 = await _context.SaveChangesAsync();

                return(response1 >= 1);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 2
0
        public async Task <bool> AddLoginUser(LoginTable loginUser)
        {
            _context.LoginTable.Add(loginUser);
            try
            {
                var response = await _context.SaveChangesAsync();

                return(response >= 1);
            }
            catch (DbUpdateException ex)
            {
                throw new DbUpdateException(ex.Message);
            }
        }
Exemplo n.º 3
0
        public async Task <bool> AddCategory(Categories categories)
        {
            try
            {
                _context.Categories.Add(categories);
                var response = await _context.SaveChangesAsync();

                return(response >= 1);
            }
            catch (DbUpdateException ex)
            {
                throw new DbUpdateException(ex.Message);
            }
        }
        public async Task <bool> AddPurchasedOptionType(PurchaseOptionType purchasedOptionType)
        {
            try
            {
                _context.PurchaseOptionType.Add(purchasedOptionType);
                var response = await _context.SaveChangesAsync();

                return(response >= 1);
            }
            catch (DbUpdateException ex)
            {
                throw new DbUpdateException(ex.Message);
            }
        }
Exemplo n.º 5
0
        public async Task <bool> AddWebinar(Webinars webinar)
        {
            try
            {
                webinar.FacultyLocalId = _context.Faculties.FirstOrDefaultAsync(faculty => faculty.Id == webinar.FacultyId).Result.LocalId;
                _context.Webinars.Add(webinar);
                var response = await _context.SaveChangesAsync();

                return(response >= 1);
            }
            catch (DbUpdateException ex)
            {
                throw new DbUpdateException(ex.Message);
            }
        }
Exemplo n.º 6
0
        public async Task <bool> AddFaculty(Faculties faculty)
        {
            try
            {
                faculty.IsCurrent       = true;
                faculty.BecameFacultyOn = DateTime.Now;
                _context.Faculties.Add(faculty);
                var response = await _context.SaveChangesAsync();

                return(response >= 1);
            }
            catch (DbUpdateException ex)
            {
                throw new DbUpdateException(ex.Message);
            }
        }
Exemplo n.º 7
0
        public async Task <bool> AddWebinarPurchasedOptionsDetails(WebinarPurchasedOptionsDetails webinarPurchasedOptionsDetails)
        {
            try
            {
                webinarPurchasedOptionsDetails.WebinarLocalId = _context.Webinars
                                                                .FirstOrDefaultAsync((webinar) => webinar.Id == webinarPurchasedOptionsDetails.WebinarId).Result.LocalId;
                _context.WebinarPurchasedOptionsDetails.Add(webinarPurchasedOptionsDetails);
                var response = await _context.SaveChangesAsync();

                return(response >= 1);
            }
            catch (DbUpdateException ex)
            {
                throw new DbUpdateException(ex.Message);
            }
        }
Exemplo n.º 8
0
        public async Task <bool> DeleteItemsFromCart(String id)
        {
            try
            {
                var cartItem = await _context.CartItems.FirstOrDefaultAsync(cartItem => cartItem.Id == new Guid(id));

                _context.CartItems.Remove(cartItem);
                var response = await _context.SaveChangesAsync();

                return(response >= 1);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 9
0
        public async Task <Guid> AddComapny(Company company)
        {
            try
            {
                _context.Company.Add(company);
                var response = await _context.SaveChangesAsync();

                return(response >= 1 ? company.Id : throw new Exception("Error in adding new company"));
            }
            catch (DbUpdateException ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 10
0
        public async Task <bool> AddWebinarType(WebinarTypes webinarType)
        {
            try
            {
                _context.WebinarTypes.Add(webinarType);
                var response = await _context.SaveChangesAsync();

                return(response >= 1);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 11
0
        public async Task <int> AddOrders(Orders order)
        {
            var orderItems = order.OrderItems;

            order.UserLocalId = _context.UserTable.FirstOrDefaultAsync(user => user.Id == order.UserId).Result.LocalId;
            order.OrderItems  = null;
            _context.Orders.Add(order);
            try
            {
                var insertionCount = 0;
                var response       = await _context.SaveChangesAsync();

                if (response >= 1)
                {
                    foreach (OrderItems orderItems1 in orderItems)
                    {
                        orderItems1.PurchaseOption = null;
                        orderItems1.OrderId        = order.Id;
                        orderItems1.OrderLocalId   = order.LocalId;
                        orderItems1.Webinar        = null;
                        _context.OrderItems.Add(orderItems1);
                        var saveChanges = _context.SaveChanges();
                        if (saveChanges >= 1)
                        {
                            var cartItem = await _context.CartItems
                                           .Include(cartItem => cartItem.Cart)
                                           .FirstOrDefaultAsync(cartItems => cartItems.WebinarId == orderItems1.WebinarId && cartItems.PurchaseOptionId == orderItems1.PurchaseOptionId && cartItems.Cart.UserId == order.UserId);

                            if (cartItem != null)
                            {
                                _context.CartItems.Remove(cartItem);
                                _context.SaveChanges();
                            }
                            insertionCount++;
                        }
                        else
                        {
                            throw new Exception("Error in updating");
                        }
                    }
                }
                return(insertionCount == orderItems.Count()? order.LocalId : throw new Exception("Error in updating all the items"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }