Exemple #1
0
        string IAccountService.Register(RegisterRequest registerRequest, string origin)
        {
            if (_context.account.Any(x => x.Email == registerRequest.Email))
            {
                return("Email is Already Registered");
            }
            if (_context.account.Any(x => x.UserName == registerRequest.UserName))
            {
                return("User Name is Already Registered");
            }


            var account = new Account()
            {
                UserName               = registerRequest.UserName,
                Email                  = registerRequest.Email,
                IsVerified             = false,
                FirstName              = registerRequest.FirstName,
                LastName               = registerRequest.LastName,
                Role                   = _context.role.FirstOrDefault(x => x.Id == registerRequest.RoleId),
                EmailVerificationToken = randomTokenString(),
                Phone                  = registerRequest.PhoneNumber,
                PasswordInHash         = BC.HashPassword(registerRequest.Password),
                RegisteredOn           = DateTime.UtcNow
            };



            _context.account.Add(account);
            _context.SaveChanges();


            sendVerificationEmail(account, origin);
            return("Registered Successfully");
        }
Exemple #2
0
        public string AddToCart(int userId, long productId)
        {
            using (_context)
            {
                try
                {
                    List <Product> listOfProducts;


                    _context.product.Include(acc => acc.Category).ToList();
                    _context.product.Include(acc => acc.productDesign).ThenInclude(acc => acc.product_design_images).ThenInclude(acc => acc.ProductImage).ToList();
                    _context.product.Include(acc => acc.productDesign).ThenInclude(acc => acc.productColor).ToList();
                    _context.product.Include(acc => acc.productDesign).ThenInclude(acc => acc.productSize).ToList();

                    _context.product.Include(acc => acc.product_images).ToList();
                    _context.product.Include(acc => acc.StichingType).ToList();
                    _context.product.Include(acc => acc.Fabric).ToList();
                    _context.product.Include(acc => acc.Vendor).ToList();

                    listOfProducts = _context.product.ToList();



                    CartItem cartItem = new CartItem()
                    {
                        product = listOfProducts.Where(e => e.Product_ID == productId).FirstOrDefault()
                    };
                    if (cartItem == null)
                    {
                        return("No product exist please choose a right product");
                    }
                    Cart cartOfUser = _context.cart.Where(e => e.AccountId == userId).Include(e => e.cartItems).FirstOrDefault();
                    if (cartOfUser == null)
                    {
                        _context.cart.Add(new Cart()
                        {
                            AccountId = userId,
                            account   = _context.account.Where(e => e.Id == userId).FirstOrDefault(),
                            cartItems = new List <CartItem>()
                            {
                                cartItem
                            }
                        });
                    }
                    else
                    {
                        cartOfUser.cartItems.Add(cartItem);
                    }

                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    return("Unable to add due to exception as >>> " + e.Message);
                }
            }

            return("Saved Successfully");
        }
Exemple #3
0
        public string AddCategory(CategoryDTO catDTO)
        {
            Categories cat = new Categories();

            cat.category_value = catDTO.Category_Value;

            _context.categories.Add(cat);
            _context.SaveChanges();
            return("Category Added Succesfully");
        }
Exemple #4
0
        string IAccountService.Register(RegisterRequest registerRequest, string origin)
        {
            if (_context.Account.Any(x => x.Email == registerRequest.Email))
            {
                return("Email is Already Registered");
                // send already registered error in email to prevent account enumeration
                //sendAlreadyRegisteredEmail(model.Email, origin);
                // return;
            }

            // map model to new account object
            var account = new Account()
            {
                Id         = 10,
                UserName   = registerRequest.UserName,
                Email      = registerRequest.Email,
                IsVerified = false,
                FirstName  = registerRequest.FirstName,
                LastName   = registerRequest.LastName,
                //Role = new Role() {Id = 1,_role = UserRoles.endUser_customer}
            };


            //account.Role = new Role() {Id = 1,_role=Roles. };
            account.RegisteredOn = DateTime.UtcNow;
            // account.VerificationToken = randomTokenString();

            // hash password
            account.PasswordInHash = BC.HashPassword(registerRequest.Password);

            // save account
            _context.Account.Add(account);
            _context.SaveChanges();

            // send email
            sendVerificationEmail(account, origin);
            return("Registered Successfully");
        }
Exemple #5
0
 public string AddVendor(Vendor vnd)
 {
     _context.vendor.Add(vnd);
     _context.SaveChanges();
     return("added");
 }