コード例 #1
0
        public async Task <IActionResult> Add(BrandModel model)
        {
            int langId = HttpContext.GetLanguage("adminLangId");

            if (ModelState.IsValid && Checker.CheckList(model.Categories))
            {
                #region Create Brand and Some CategoryBrands
                Brand brand = new Brand();
                brand.Name = model.BrandName;
                db.Brands.Add(brand);
                for (var i = 0; i < model.Categories.Count; i++)
                {
                    CategoryBrand categoryBrand = new CategoryBrand();
                    categoryBrand.BrandId    = brand.Id;
                    categoryBrand.CategoryId = model.Categories[i];

                    db.CategoryBrands.Add(categoryBrand);
                }

                await db.SaveChangesAsync();

                #endregion

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError("", "Make sure that you fill al required blanks");
                return(RedirectToAction(nameof(Add)));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Add(List <string> Names, int CategoryId)
        {
            if (Checker.CheckList(Names))
            {
                Subcategory subcategory = new Subcategory();
                db.Subcategories.Add(subcategory);
                List <Language> languages = db.Languages.ToList();
                for (int i = 0; i < languages.Count; i++)
                {
                    SubcategoryLanguage subcategoryLanguage = new SubcategoryLanguage();
                    subcategoryLanguage.Subcategory            = subcategory;
                    subcategoryLanguage.SubcategoryId          = subcategory.Id;
                    subcategoryLanguage.Subcategory.CategoryId = CategoryId;
                    subcategoryLanguage.Name       = Names[i];
                    subcategoryLanguage.LanguageId = languages[i].Id;
                    db.SubcategoryLanguages.Add(subcategoryLanguage);
                }
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError("", "Fill all Blanks");
                return(View());
            }
        }
コード例 #3
0
        public async Task <JsonResult> Add(List <string> Data)
        {
            if (Checker.CheckList(Data))
            {
                About about = new About();
                await db.Abouts.AddAsync(about);

                var langCount = await db.Languages.ToListAsync();

                for (int i = 0; i < langCount.Count; i++)
                {
                    AboutLanguage aboutLanguage = new AboutLanguage()
                    {
                        Language   = langCount[i],
                        About      = about,
                        LanguageId = langCount[i].Id,
                        Text       = Data[i]
                    };

                    await db.AboutLanguages.AddAsync(aboutLanguage);

                    await db.SaveChangesAsync();
                }

                return(Json(new { status = 200 }));
            }
            else
            {
                return(Json(new { status = 400 }));
            }
        }
コード例 #4
0
        public async Task <JsonResult> Add(List <string> Data)
        {
            if (Checker.CheckList(Data))
            {
                Terms term = new Terms();
                db.Terms.Add(term);
                var langCount = await db.Languages.ToListAsync();

                for (int i = 0; i < langCount.Count; i++)
                {
                    TermsLanguage termsLanguage = new TermsLanguage()
                    {
                        Language   = langCount[i],
                        Terms      = term,
                        TermsId    = term.Id,
                        LanguageId = langCount[i].Id,
                        Data       = Data[i]
                    };

                    db.TermsLanguages.Add(termsLanguage);
                    await db.SaveChangesAsync();
                }

                return(Json(new { status = 200 }));
            }
            else
            {
                return(Json(new { status = 400 }));
            }
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("Id,Logo,Phone,Email,Description,Facebook,Twitter,Instagram")] Setting setting)
        {
            if (ModelState.IsValid)
            {
                _context.Add(setting);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(setting));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price")] Shipping shipping)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shipping);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shipping));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("Id,PhotoPath,Heading,Title,Link")] Ad ad)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ad);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ad));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("Id,Name")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
コード例 #9
0
        public async Task <IActionResult> Add(Size size)
        {
            if (ModelState.IsValid)
            {
                db.Sizes.Add(size);
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError("", "Name is required");
                return(View(size));
            }
        }
コード例 #10
0
        public static async Task UserCreator(IServiceScope scope, DahlizDb db)
        {
            UserManager <User>         userManager = scope.ServiceProvider.GetRequiredService <UserManager <User> >();
            RoleManager <IdentityRole> roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();

            if (!db.Users.Any() && !db.Roles.Any())
            {
                User user = new User()
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                IdentityResult createResult = await userManager.CreateAsync(user, "Admin123@");

                if (createResult.Succeeded)
                {
                    IdentityResult roleCreaateResult = await roleManager.CreateAsync(new IdentityRole { Name = "Admin" });

                    if (roleCreaateResult.Succeeded)
                    {
                        IdentityResult roleAttachResult = await userManager.AddToRoleAsync(user, "Admin");

                        if (roleAttachResult.Succeeded)
                        {
                            await db.SaveChangesAsync();
                        }
                    }
                }
            }
        }
コード例 #11
0
        public async Task <IActionResult> Add(List <string> Names)
        {
            List <Language> languages = await db.Languages.ToListAsync();

            if (Checker.CheckList(Names))
            {
                Color color = new Color();
                db.Colors.Add(color);
                for (int i = 0; i < languages.Count; i++)
                {
                    ColorLanguage colorLanguage = new ColorLanguage();
                    colorLanguage.Name       = Names[i];
                    colorLanguage.LanguageId = languages[i].Id;
                    colorLanguage.ColorId    = color.Id;
                    db.ColorLanguage.Add(colorLanguage);
                }
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError("", "Fill all Blanks");
                return(View());
            }
        }
コード例 #12
0
        public async Task <IActionResult> Add(List <string> Texts, string Link)
        {
            List <Language> languages = await db.Languages.ToListAsync();

            if (Checker.CheckList(Texts))
            {
                Noti noti = new Noti();
                noti.Link = Link;
                db.Noti.Add(noti);
                for (int i = 0; i < languages.Count; i++)
                {
                    NotiLanguage notiLanguage = new NotiLanguage();
                    notiLanguage.Text       = Texts[i];
                    notiLanguage.LanguageId = languages[i].Id;
                    notiLanguage.NotiId     = noti.Id;

                    db.NotiLanguage.Add(notiLanguage);
                }
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError("", "Fill all Blanks");
                return(View());
            }
        }
コード例 #13
0
        public async Task <IActionResult> Add(List <string> Names)
        {
            foreach (var item in Names)
            {
                if (item == null)
                {
                    ModelState.AddModelError("", "Name is required");
                    return(View());
                }
            }
            Category category = new Category();

            db.Categories.Add(category);
            List <Language> languages = db.Languages.ToList();

            for (int i = 0; i < languages.Count(); i++)
            {
                CategoryLanguage categoryLanguage = new CategoryLanguage();
                categoryLanguage.Name       = Names[i];
                categoryLanguage.CategoryId = category.Id;
                categoryLanguage.LanguageId = languages[i].Id;
                db.CategoryLanguages.Add(categoryLanguage);
            }
            await db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #14
0
        public async Task <IActionResult> Add(Slide model)
        {
            if (ModelState.IsValid)
            {
                Slide slide = new Slide()
                {
                    Text      = model.Text,
                    Title     = model.Title,
                    PhotoPath = model.PhotoPath
                };

                await db.Slides.AddAsync(slide);

                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError("", "Fill all blanks");
                return(View(model));
            }
        }
コード例 #15
0
        public async Task <IActionResult> Checkout(string cardType, string Zip, string City, string Address)
        {
            string user_id = HttpContext.Session.GetString("user_id");

            if (user_id != null)
            {
                List <Card> cards = HttpContext.Session.GetObjectFromJson <Card>("Card") as List <Card>;
                if (cardType != null && Zip != null && City != null && Address != null)
                {
                    #region Make CPaymentItem For API
                    decimal      amount        = Convert.ToDecimal(HttpContext.Session.GetString("Total"));
                    decimal      shippingPrice = amount - cards.Sum(c => c.Quantity * c.Price);
                    CPaymentItem cPaymentItem  = new CPaymentItem();
                    cPaymentItem.merchantName = configuration["PaymentInformation:MerchantName"];
                    cPaymentItem.amount       = (int)(amount * 100);
                    cPaymentItem.cardType     = cardType;
                    cPaymentItem.lang         = "lv";
                    cPaymentItem.description  = "Product";
                    cPaymentItem.hashCode     = GetMD5HashCode(configuration["PaymentInformation:AuthKey"] +
                                                               configuration["PaymentInformation:MerchantName"] +
                                                               cPaymentItem.cardType +
                                                               cPaymentItem.amount +
                                                               cPaymentItem.description);
                    #endregion

                    #region Create Payment
                    List <Payment> userOrders = new List <Payment>();
                    for (var i = 0; i < cards.Count; i++)
                    {
                        Payment currentPayment = new Payment();
                        //City
                        currentPayment.City = City;
                        //Postal Code
                        currentPayment.PostalCode = Zip;

                        //Address
                        currentPayment.Address = Address;

                        currentPayment.ProductDiscount = cards[i].DiscountPercent;

                        //User
                        string userId = HttpContext.Session.GetString("user_id");
                        User   user   = db.Users.Where(u => u.Id == userId).FirstOrDefault();
                        currentPayment.UserName    = user.Name;
                        currentPayment.UserSurname = user.Surname;
                        currentPayment.UserEmail   = user.Email;
                        currentPayment.UserId      = user.Id;
                        //If user address was null on register  then on payment we take address and append to it
                        user.Address = user.Address == null ? Address : user.Address;


                        //Cardtype
                        CardType type = await db.CardTypes.Where(c => c.Key == cardType).FirstOrDefaultAsync();

                        currentPayment.CardType = type;

                        //Product
                        Product orderedProduct = await db.Products.Where(p => p.Id == cards[i].Id).FirstOrDefaultAsync();

                        ProductLanguage productLanguage = await db.ProductLanguages
                                                          .Include(l => l.Language)
                                                          .Where(p => p.Language.Key == "az" && p.ProductId == orderedProduct.Id)
                                                          .FirstOrDefaultAsync();

                        currentPayment.ProductName  = productLanguage.Name;
                        currentPayment.ProductPrice = orderedProduct.Price;
                        currentPayment.ProductId    = orderedProduct.Id;

                        //Datetime
                        currentPayment.Date = DateTime.Now;

                        //Shipping Price
                        currentPayment.ShippingPrice = shippingPrice;

                        //ProductSize
                        currentPayment.ProductSize = cards[i].SizeName;

                        //Quantity
                        currentPayment.Count = cards[i].Quantity;

                        //Total Price
                        if (currentPayment.ProductDiscount != 0 || currentPayment.ProductDiscount != null)
                        {
                            currentPayment.TotalPrice = (decimal)(cards[i].Price * currentPayment.ProductDiscount / 100) * cards[i].Quantity;
                        }
                        else
                        {
                            currentPayment.TotalPrice = cards[i].Price * cards[i].Quantity;
                        }

                        //Status
                        currentPayment.Status = 2;

                        //TransactionId
                        currentPayment.TransactionId = cPaymentItem.hashCode;

                        userOrders.Add(currentPayment);
                    }
                    await db.Payments.AddRangeAsync(userOrders);

                    await db.SaveChangesAsync();

                    #endregion

                    #region Send Web Request
                    var jsonValues = JsonConvert.SerializeObject(cPaymentItem);

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(configuration["PaymentInformation:RequestToServerUrlGetPaymentKey"]);
                    request.ContentType = "application/json; charset=utf-8";
                    request.Method      = "POST";
                    request.Accept      = "application/json";
                    using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
                    {
                        streamWriter.Write(jsonValues);
                        streamWriter.Flush();
                    }
                    #endregion

                    #region Get Web Response
                    string          responseData = string.Empty;
                    HttpWebResponse response     = (HttpWebResponse)request.GetResponse();

                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        responseData = reader.ReadToEnd();
                    }
                    CRespGetPaymentKey cRespPymnt = (CRespGetPaymentKey)JsonConvert.DeserializeObject(responseData, typeof(CRespGetPaymentKey));

                    #endregion

                    if (cRespPymnt.status.code != 1)
                    {
                        throw new Exception("Error while getting paymentKey, code=" + cRespPymnt.status.code + ", message=" + cRespPymnt.status.message);
                    }

                    return(Redirect(configuration["PaymentInformation:ReuqestToServerUrlPayPage"] + cRespPymnt.paymentKey));
                }
                else
                {
                    return(RedirectToAction("Error", "Payment"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
コード例 #16
0
        public async Task <IActionResult> ExternalLoginCallBack()
        {
            var authResult = await HttpContext.AuthenticateAsync("TempCookie");

            if (!authResult.Succeeded)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var email   = authResult.Principal.FindFirstValue(ClaimTypes.Email);
            var name    = authResult.Principal.FindFirstValue(ClaimTypes.GivenName);
            var surname = authResult.Principal.FindFirstValue(ClaimTypes.Surname);

            await HttpContext.SignOutAsync("TempCookie");

            var findUserResult = await userManager.FindByEmailAsync(email);

            var userNameGuid = db.Users.Count();

            if (findUserResult == null)
            {
                var user = new User()
                {
                    Email          = email,
                    Surname        = surname,
                    Name           = name,
                    UserName       = name + surname + userNameGuid,
                    EmailConfirmed = true
                };
                var createUserResult = await userManager.CreateAsync(user);

                if (createUserResult.Succeeded)
                {
                    HttpContext.SetUserInfoToSession("user_name", user.Name);
                    HttpContext.SetUserInfoToSession("user_id", user.Id);
                    HttpContext.SetUserInfoToSession("user_surname", user.Surname);

                    await signInManager.SignInAsync(user, true);

                    await db.SaveChangesAsync();

                    return(RedirectToAction("Detail", "Account"));
                }
                else
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
            else
            {
                var user = await userManager.FindByEmailAsync(email);

                HttpContext.SetUserInfoToSession("user_name", user.Name);
                HttpContext.SetUserInfoToSession("user_id", user.Id);
                HttpContext.SetUserInfoToSession("user_surname", user.Surname);

                await signInManager.SignInAsync(user, true);

                return(RedirectToAction("Detail", "Account"));
            }
        }
コード例 #17
0
        public async Task <IActionResult> Edit(ProductModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.SubCategoryId != 0 && model.CategoryId != 0)
                {
                    #region Product Static Properties Edit
                    Product product = db.Products.Where(p => p.Id == model.ProductId).FirstOrDefault();

                    product.Price           = Math.Ceiling(Convert.ToDecimal(model.Price));
                    product.SubcategoryId   = model.SubCategoryId;
                    product.Quantity        = 0;
                    product.DiscountPercent = Convert.ToInt32(model.DiscountPercent);
                    #endregion

                    List <ProductLanguage> productLanguages = await db.ProductLanguages
                                                              .Where(pl => pl.ProductId == product.Id)
                                                              .ToListAsync();

                    List <ProductSizeCount> productSizeCounts = await db.ProductSizeCounts
                                                                .Where(ps => ps.ProductId == product.Id)
                                                                .Include(ps => ps.Size)
                                                                .ToListAsync();

                    List <ProductColor> productColors = await db.ProductColors
                                                        .Where(pc => pc.ProductId == product.Id)
                                                        .Include(pc => pc.Color)
                                                        .ToListAsync();

                    List <ProductPhoto> productPhotos = await db.ProductPhotos.Where(pp => pp.Product == product).ToListAsync();

                    if (Checker.CheckList(model.Names) && Checker.CheckList(model.Sizes) &&
                        Checker.CheckList(model.Count) &&
                        Checker.CheckList(model.Descriptions))
                    {
                        #region Product Language Edit
                        //Product Language Edit
                        for (int i = 0; i < productLanguages.Count; i++)
                        {
                            productLanguages[i].Name        = model.Names[i];
                            productLanguages[i].Description = model.Descriptions[i];
                        }

                        #endregion



                        #region Product Size Edit
                        //Product Size Edit
                        if (model.Sizes.Count > productSizeCounts.Count)
                        {
                            for (int i = 0; i < model.Sizes.Count; i++)
                            {
                                if (i + 1 > productSizeCounts.Count)
                                {
                                    ProductSizeCount productSizeCount = new ProductSizeCount();
                                    productSizeCount.ProductId = product.Id;
                                    productSizeCount.SizeId    = model.Sizes[i];
                                    productSizeCount.Count     = Convert.ToInt32(model.Count[i]);
                                    product.Quantity          += Convert.ToInt32(model.Count[i]);
                                    db.ProductSizeCounts.Add(productSizeCount);
                                }
                                else
                                {
                                    productSizeCounts[i].SizeId = model.Sizes[i];
                                }
                            }
                        }
                        else if (model.Sizes.Count == productSizeCounts.Count)
                        {
                            for (int i = 0; i < model.Sizes.Count; i++)
                            {
                                productSizeCounts[i].SizeId = model.Sizes[i];
                                productSizeCounts[i].Count  = Convert.ToInt32(model.Count[i]);
                                product.Quantity           += Convert.ToInt32(model.Count[i]);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < productSizeCounts.Count; i++)
                            {
                                if (i + 1 <= model.Sizes.Count)
                                {
                                    productSizeCounts[i].SizeId = model.Sizes[i];
                                    productSizeCounts[i].Count  = Convert.ToInt32(model.Count[i]);
                                    product.Quantity           += Convert.ToInt32(model.Count[i]);
                                }
                                else
                                {
                                    ProductSizeCount productSizeCount = db.ProductSizeCounts
                                                                        .Where(ps => ps.SizeId == productSizeCounts[i].SizeId)
                                                                        .FirstOrDefault();
                                    db.ProductSizeCounts.Remove(productSizeCount);
                                }
                            }
                        }

                        #endregion


                        #region Photo Edit
                        if (model.DeletePhotos != null)
                        {
                            //then we have to delete old photos
                            foreach (var deletePhoto in model.DeletePhotos)
                            {
                                ProductPhoto productPhoto = await db.ProductPhotos
                                                            .Where(pp => pp.Product == product && pp.PhotoPath == deletePhoto)
                                                            .FirstOrDefaultAsync();

                                if (productPhoto != null)
                                {
                                    db.ProductPhotos.Remove(productPhoto);
                                }
                            }
                        }
                        if (model.Photos != null)
                        {
                            //then we have to add new photos
                            foreach (var photo in model.Photos)
                            {
                                if (photo != null)
                                {
                                    if (!productPhotos.Select(p => p.PhotoPath).Contains(photo))
                                    {
                                        ProductPhoto productPhoto = new ProductPhoto();
                                        productPhoto.Product   = product;
                                        productPhoto.PhotoPath = photo;
                                        db.ProductPhotos.Add(productPhoto);
                                    }
                                }
                            }
                        }
                        #endregion

                        await db.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Make Sure that you fill al required blanks!");
                        return(RedirectToAction(nameof(Edit)));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Category or Subcategory not selected");
                    return(RedirectToAction(nameof(Edit)));
                }
            }
            else
            {
                ModelState.AddModelError("", "Make Sure that you fill al required blanks!");
                return(RedirectToAction(nameof(Edit)));
            }
        }