public async Task <IActionResult> Edit(int id, [Bind("JewelryId,UserId,Date,Amount,Reference,Id,Country")] Purchase purchase)
        {
            if (id != purchase.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(purchase);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PurchaseExists(purchase.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["JewelryId"] = new SelectList(_context.Jewelry, "Id", "Name", purchase.JewelryId);
            ViewData["UserId"]    = new SelectList(_context.Users, "Id", "Id", purchase.UserId);
            return(View(purchase));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Weight,Price,Cart,Size,Description,Amount,Discount,Id,Diamonds,ImagePath,Name,CategoryId,SetId")] Jewelry jewelry)
        {
            if (id != jewelry.Id)
            {
                return(NotFound());
            }

            if (Account.isAdmin(User))
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        ColmanInternetiotContext newContext = new ColmanInternetiotContext();

                        int?currAmount = newContext.Jewelry.First(x => x.Id == jewelry.Id).Amount;

                        _context.Update(jewelry);
                        await _context.SaveChangesAsync();

                        if (currAmount != null)
                        {
                            string postToFacebook = ("לתכשיט " + jewelry.Name + " נוספו " + (jewelry.Amount - int.Parse(currAmount.ToString())) + " פריטים חדשים. היכנסו לאתר בשביל לקנות");

                            FacebookPost post = new FacebookPost();

                            post.PublishToFacebookNoPhoto(postToFacebook);
                        }
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!JewelryExists(jewelry.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    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> Edit(int id, [Bind("Name,Address,CoordinateLat,CoordinateLng,ManagerId,Id")] Branch branch)
        {
            if (id != branch.Id)
            {
                return(NotFound());
            }

            if (Account.isAdmin(User) || isStoreOwner(User, id))
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(branch);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!BranchExists(branch.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction("Index"));
                }

                ViewData["ManagerId"] = new SelectList(_context.Users, "Id", "Id", branch.ManagerId);
                return(View(branch));
            }
            else
            {
                return(new RedirectToActionResult("NotAuthorized", "Home", null));
            }
        }
Пример #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,NameId,Email,FName,LName,Name,Gender,IsAdmin,CreationDate")] Users users)
        {
            if (Account.isLoggedIn(HttpContext.User))
            {
                if (Account.isAdmin(HttpContext.User))
                {
                    if (id != users.Id)
                    {
                        return(NotFound());
                    }

                    if (ModelState.IsValid)
                    {
                        try
                        {
                            _context.Update(users);
                            await _context.SaveChangesAsync();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!UsersExists(users.NameId))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                        return(RedirectToAction("Index"));
                    }
                    return(View(users));
                }
            }

            return(new RedirectToActionResult("NotAuthorized", "Home", null));
        }