Exemplo n.º 1
0
        public async Task <DbProduct> Save(DbProduct product)
        {
            if (!_permissionService.HasPermissionToChangeProducts())
            {
                throw new InvalidOperationException("Нет прав доступа для изменения Товаров");
            }

            if (product.Id != Guid.Empty)
            {
                var existProuct = await _context.Products.Where(x => x.Id == product.Id).FirstOrDefaultAsync();

                if (existProuct == null)
                {
                    throw new InvalidOperationException("Позиция не найдена.");
                }
                Update(existProuct, product);
                _context.Update(existProuct);
                await _context.SaveChangesAsync();

                return(existProuct);
            }
            product.OwnerId = Guid.Parse(_httpContextAccessor.HttpContext.User.Claims.First(c => c.Type == "UserId").Value);
            _context.Products.Add(product);
            await _context.SaveChangesAsync();

            return(product);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,EmployeeId,OrderDate")] Order order)
        {
            if (id != order.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmployeeId"] = new SelectList(_context.employees, "ID", "ID", order.EmployeeId);
            return(View(order));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Login,Password,RoleId,IsBlocked")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoleId"] = new SelectList(_context.Roles, "Id", "Id", user.RoleId);
            return(View(user));
        }
        public async Task <IActionResult> Edit(string id, [Bind("Id,Password,Fullname,Email,Photo,Activated")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,CategoryId")] Filter filter)
        {
            if (id != filter.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(filter);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FilterExists(filter.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(filter));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FullName,Company_Name,Company_Phone,Contat_Name,Contact_Title,Address,Contact_Date")] Deliver deliver)
        {
            if (id != deliver.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(deliver);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DeliverExists(deliver.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(deliver));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,FilterId")] FilterAddititon filterAddititon)
        {
            if (id != filterAddititon.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(filterAddititon);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FilterAddititonExists(filterAddititon.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(FilterSearch), "Filters", new { filterId = filterAddititon.FilterId }));
            }
            return(View(filterAddititon));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CustomerId,OrderDate,RequireDate,Receiver,Address,Description,Amount")] Order order)
        {
            if (id != order.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Id", order.CustomerId);
            return(View(order));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Product_Name,Unit_Price,UnitInStock,UnitInOrder,LastDate,EnterDate,DeliverId,CategoryId")] Product product)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.categories, "Id", "Id", product.CategoryId);
            ViewData["DeliverId"]  = new SelectList(_context.delivers, "Id", "Id", product.DeliverId);
            return(View(product));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,OrderId,ProductId,Quetity,UnitPrice,Descount")] OrderDetails orderDetails)
        {
            if (id != orderDetails.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(orderDetails);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderDetailsExists(orderDetails.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.orders, "Id", "Id", orderDetails.OrderId);
            ViewData["ProductId"] = new SelectList(_context.products, "Id", "Id", orderDetails.ProductId);
            return(View(orderDetails));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Type,Amount,Price,AddedOn")] Product product)
        {
            if (product.Id != id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductInStock(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(View());
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Name,Email,Phone,Comment,DateTime,ClientId")] Order order)
        {
            if (id != order.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Name,Logo,Email,Phone")] supplier supplier)
        {
            if (id != supplier.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(supplier);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!supplierExists(supplier.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
Exemplo n.º 14
0
        public async Task <DbCategory> SaveCategory(DbCategory category)
        {
            if (!_permissionService.HasPermissionToChangeCategories())
            {
                throw new InvalidOperationException("Нет прав доступа для изменения категорий");
            }

            if (category.Id != Guid.Empty)
            {
                var existCategory = await _context.Categories.Where(x => x.Id == category.Id).FirstOrDefaultAsync();

                if (existCategory == null)
                {
                    throw new InvalidOperationException("Категория не найдена.");
                }
                Update(existCategory, category);
                _context.Update(existCategory);
                await _context.SaveChangesAsync();

                return(existCategory);
            }
            else
            {
                _context.Categories.Add(category);
            }
            await _context.SaveChangesAsync();

            return(category);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Pasition_Name")] Position position)
        {
            if (id != position.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(position);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PositionExists(position.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(position));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Product,Count,Price,DateTime")] Provider provider)
        {
            if (id != provider.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(provider);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProviderExists(provider.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(provider));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Category_Name,Description,PhotoPath")] Category category)
        {
            if (id != category.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title")] Brand brand)
        {
            if (id != brand.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(brand);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BrandExists(brand.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(brand));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Fullname,BirthDay,HireDay,Address,Phone_Nomer,Email,Photo_Path,PositionId")] Employee employee)
        {
            if (id != employee.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employee);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PositionId"] = new SelectList(_context.positions, "Id", "Id", employee.PositionId);
            return(View(employee));
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Email,Phone")] Client client)
        {
            if (id != client.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(client);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
Exemplo n.º 21
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,MainImage,IsDiscount,IsMane,CategoryId,Price,BrandId,ProviderId")] Product product, IFormFile uploadedFile)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }
            //изменение изображения
            _context.Entry(product).State = EntityState.Modified;
            if (uploadedFile != null)
            {
                string path = "/files/" + uploadedFile.FileName;
                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(fileStream);
                }
                product.MainImage = path;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Exemplo n.º 22
0
        public async Task <IActionResult> SetRole([FromQuery] Guid userId, [FromQuery] int role)
        {
            var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == userId);

            if (user != null)
            {
                user.Role = (UserRole)role;
                _context.Update(user);
                await _context.SaveChangesAsync();
            }

            return(Redirect("/User/GetRegistry"));
        }
Exemplo n.º 23
0
 // Uppdatera en annons
 public string UpdateAdv(Advertisement adv)
 {
     try
     {
         _context.Update(adv);
         _context.SaveChanges();
     }
     catch (DbUpdateConcurrencyException)
     {
         return("Uppdatering av annonsen misslyckades");
     }
     return("OK");
 }
Exemplo n.º 24
0
        public async Task <IActionResult> Create([Bind("Id,Name,UnitBrief,UnitPrice,Image,ProductDate,Available,Description,CategoryId,SupplierId,Quantity,Discount,Special,Latest,Views")] Product product, IFormFile ful)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Admin/images", product.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await ful.CopyToAsync(stream);
                }
                product.Image = product.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                _context.Update(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", product.CategoryId);
            ViewData["SupplierId"] = new SelectList(_context.Suppliers, "Id", "Id", product.SupplierId);
            return(View(product));
        }
Exemplo n.º 25
0
 public JsonResult Put(string table, [FromBody] JObject parameters)
 {
     try
     {
         MarketContext MC = new MarketContext();
         MC.CreateConnection();
         if (MC.Connected())
         {
             return(Json(MC.Update(table, parameters)));
         }
         else
         {
             throw new Exception("Connection failed");
         }
     }
     catch (Exception ex)
     {
         return(Json("Error: " + ex.Message));
     }
 }