public async Task <IActionResult> Create([Bind("Weight,Price,Cart,Size,Description,Amount,Discount,Id,Diamonds,ImagePath,Name,CategoryId,SetId")] Jewelry jewelry)
        {
            if (Account.isAdmin(User))
            {
                if (ModelState.IsValid)
                {
                    _context.Add(jewelry);
                    await _context.SaveChangesAsync();

                    string postToFacebook = ("התכשיט " + jewelry.Name + " נוסף לחנות. יש " + jewelry.Amount + " פריטים. היכנסו לאתר בשביל לקנות");

                    FacebookPost post = new FacebookPost();

                    post.PublishToFacebookNoPhoto(postToFacebook);

                    return(RedirectToAction("Index"));
                }

                ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", jewelry.CategoryId);
                ViewData["SetId"]      = new SelectList(_context.JewelrySet, "Id", "Name", jewelry.SetId);
                return(View(jewelry));
            }
            else
            {
                return(new RedirectToActionResult("NotAuthorized", "Home", null));
            }
        }
        public async Task <IActionResult> Create([Bind("Name,Address,CoordinateLat,CoordinateLng,ManagerId,Id")] Branch branch)
        {
            if (Account.isAdmin(User))
            {
                if (ModelState.IsValid)
                {
                    _context.Add(branch);
                    await _context.SaveChangesAsync();

                    string postToFacebook = ("החנות " + branch.Name + " התווספה. מוזמנים לבקר בכתובת " + branch.Address + ". בואו בהמוניכם !!!");

                    FacebookPost post = new FacebookPost();

                    post.PublishToFacebookNoPhoto(postToFacebook);

                    return(RedirectToAction("Index"));
                }

                ViewData["ManagerId"] = new SelectList(_context.Users, "Id", "Id", branch.ManagerId);

                return(View(branch));
            }
            else
            {
                return(new RedirectToActionResult("NotAuthorized", "Home", null));
            }
        }
Пример #3
0
 public async void Create([Bind("Id,Email,FName,LName,Name,Gender,IsAdmin,CreationDate")] Users users)
 {
     if (ModelState.IsValid)
     {
         if (!(UsersExists(users.NameId)))
         {
             _context.Add(users);
             await _context.SaveChangesAsync();
         }
     }
 }
        public async void Create([Bind("JewelryId,UserId,Date,Amount,Reference,Id,Country")] Purchase purchase)
        {
            if (ModelState.IsValid)
            {
                _context.Add(purchase);
                await _context.SaveChangesAsync();

                Jewelry jewelry = _context.Jewelry.First(x => x.Id == purchase.JewelryId);

                jewelry.Amount -= (int)purchase.Amount;

                _context.Jewelry.Update(jewelry);
                await _context.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (Account.isAdmin(User))
            {
                if (ModelState.IsValid)
                {
                    _context.Add(category);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                return(View(category));
            }
            else
            {
                return(new RedirectToActionResult("NotAuthorized", "Home", null));
            }
        }