public async Task <User> UpdateUser(User userForUpdate)
        {
            try
            {
                User updatedUser = dbContext.User.Where(x => x.Id == userForUpdate.Id).FirstOrDefault();
                if (updatedUser != null)
                {
                    updatedUser.FirstName = userForUpdate.FirstName;
                    updatedUser.LastName  = userForUpdate.LastName;
                    updatedUser.Status    = userForUpdate.Status;

                    dbContext.Update(updatedUser);
                    await dbContext.SaveChangesAsync();

                    return(updatedUser.WithoutPassword());
                }
                else
                {
                    throw new Exception("User doesnt exist");
                }
            }
            catch (Exception ex)
            {
                // moze se dodati logger koji upisuje exceptione u neku bazu
                throw new Exception(ex.Message);
            }
        }
Esempio n. 2
0
        public ActionResult Edit(int id, [Bind("MenuID,CategoryID,Content,ContentType,CreatedBy,CreatedDate,IsDeleted,MenuDescription,MenuName,MenuPrice,StatusID,UpdatedBy,UpdatedDate")] Menu menu, ICollection <IFormFile> files)
        {
            if (id != menu.MenuID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var data = _context.Menu.SingleOrDefault(m => m.MenuID == menu.MenuID);
                    if (data != null)
                    {
                        foreach (var file in files)
                        {
                            if (file.Length > 0)
                            {
                                using (var fileStream = file.OpenReadStream())
                                    using (var ms = new MemoryStream())
                                    {
                                        fileStream.CopyTo(ms);
                                        var    fileBytes = ms.ToArray();
                                        string s         = Convert.ToBase64String(fileBytes);
                                        data.Content     = fileBytes;
                                        data.ContentType = file.ContentType;

                                        // act on the Base64 data
                                    }
                            }
                        }
                        data.MenuName        = menu.MenuName;
                        data.MenuPrice       = menu.MenuPrice;
                        data.MenuDescription = menu.MenuDescription;
                        data.CategoryID      = menu.CategoryID;
                        data.StatusID        = menu.StatusID;
                        data.UpdatedBy       = "Admin";
                        data.UpdatedDate     = DateTime.Now;
                    }
                    _context.Update(data);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MenuExists(menu.MenuID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["CategoryID"] = new SelectList(_context.Category, "CategoryID", "CategoryName", menu.CategoryID);
            ViewData["StatusID"]   = new SelectList(_context.Status, "StatusID", "StatusName", menu.StatusID);
            return(View(menu));
        }
        public async Task <IActionResult> Edit(long id, [Bind("Id,IssueTime,CustomerId,RestaurantId,IssueDate,PlannedTime,PlannedDate")] MyapiOrder myapiOrder)
        {
            if (id != myapiOrder.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(myapiOrder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MyapiOrderExists(myapiOrder.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"]   = new SelectList(_context.MyapiCustomers, "Id", "Email", myapiOrder.CustomerId);
            ViewData["RestaurantId"] = new SelectList(_context.MyapiRestaurants, "Id", "Address", myapiOrder.RestaurantId);
            return(View(myapiOrder));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,NmName,DsEmail")] TbUser tbUser)
        {
            if (id != tbUser.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tbUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TbUserExists(tbUser.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tbUser));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,EmployeeName,EmployeeStatus,Salary,PayBasis,PositionTitle")] 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)));
            }
            return(View(employee));
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(int id, Churrasco churrasco)
        {
            if (id != churrasco.ChurrascoID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(churrasco);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ChurrascoExists(churrasco.ChurrascoID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), new { id = id }));
            }
            return(View(churrasco));
        }
        public async Task <IActionResult> Edit(long id, [Bind("Id,Name,Address,LogoUrl")] MyapiRestaurant myapiRestaurant)
        {
            if (id != myapiRestaurant.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(myapiRestaurant);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MyapiRestaurantExists(myapiRestaurant.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(myapiRestaurant));
        }
Esempio n. 8
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,Name,Price,PhotoUrl,Category,Details")] MyapiProduct myapiProduct)
        {
            if (id != myapiProduct.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(myapiProduct);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MyapiProductExists(myapiProduct.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(myapiProduct));
        }
Esempio n. 9
0
        public async Task <IActionResult> Edit(int id, 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)));
            }
            return(View(product));
        }
Esempio n. 10
0
        public async Task <IActionResult> Edit(string id, [Bind("UserName,Userpassword")] Demo demo)
        {
            if (id != demo.UserName)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(demo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DemoExists(demo.UserName))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(demo));
        }
        public async Task <IActionResult> Edit(int id, [Bind("OrderID,CreatedBy,CreatedDate,Finish,IsDeleted,Name,OrderDate,TypeID,UpdateDate,UpdatedBy")] Order order)
        {
            if (id != order.OrderID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.OrderID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["TypeID"] = new SelectList(_context.Type, "TypeID", "TypeName", order.TypeID);
            return(View(order));
        }
Esempio n. 12
0
        public async Task <IActionResult> Edit(int id, Participante participante)
        {
            if (id != participante.ParticipanteID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(participante);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ParticipanteExists(participante.ParticipanteID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), "Churrascos", new { id = participante.ChurrascoID }));
            }
            return(View(participante));
        }
        public async Task <IActionResult> Edit(int id, [Bind("CategoryId,CategoryName,Description")] Category category)
        {
            if (id != category.CategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.CategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Esempio n. 14
0
        private async Task UpdateAvailable()
        {
            var list = _dbContext.Set <TestData>().Where(x => x.ProductAmount == 0).ToList();

            foreach (var i in list)
            {
                i.isAvailable = Database.Enums.IsInStock.NOT_IN_STOCK;
                _dbContext.Update(i);
            }
            list = _dbContext.Set <TestData>().Where(x => x.ProductAmount > 0).ToList();
            foreach (var i in list)
            {
                i.isAvailable = Database.Enums.IsInStock.IN_STOCK;
                _dbContext.Update(i);
            }
            await _dbContext.SaveChangesAsync();
        }
Esempio n. 15
0
        public ResponseViewModel CancelOrderItem(int id)
        {
            var data = _context.OrderItem.Find(id);

            if (data.Status == "Order")
            {
                data.Status = "Cancel";
                _context.Update(data);
                _context.SaveChanges();
                return(new ResponseViewModel {
                    Status = true
                });
            }
            else
            {
                return(new ResponseViewModel {
                    Status = false
                });
            }
        }
        public ResponseViewModel ServedOrder(int id)
        {
            var orderitem = _context.OrderItem.Find(id);

            if (orderitem.IsDeleted != true)
            {
                orderitem.Status = "Served";
                _context.Update(orderitem);
                _context.SaveChanges();
                return(new ResponseViewModel {
                    Status = true
                });
            }
            else
            {
                return(new ResponseViewModel {
                    Status = false
                });;
            }
        }
Esempio n. 17
0
        public async Task <News> UpdateNews(News newsForUpdate)
        {
            try
            {
                News updatedNews = dbContext.News.Where(x => x.Id == newsForUpdate.Id).FirstOrDefault();
                updatedNews.Title        = newsForUpdate.Title;
                updatedNews.Text         = newsForUpdate.Text;
                updatedNews.DateInserted = newsForUpdate.DateInserted;
                updatedNews.UserCreated  = newsForUpdate.UserCreated;

                dbContext.Update(updatedNews);
                await dbContext.SaveChangesAsync();

                return(updatedNews);
            }
            catch (Exception ex)
            {
                // moze se dodati logger koji upisuje exceptione u neku bazu
                throw new Exception(ex.Message);
            }
        }
 public IActionResult CreateEditUSer(UserTable model)
 {
     if (model.Id == 0)
     {
         _dbContext.Add(model);
     }
     else
     {
         _dbContext.Update(model);
     }
     _dbContext.SaveChanges();
     return(RedirectToAction("Index"));
 }
        public ActionResult Edit(int id, [Bind("StatusID,CreatedBy,CreatedDate,IsDeleted,StatusName,UpdatedBy,UpdatedDate")] Status status)
        {
            if (id != status.StatusID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var data = _context.Status.SingleOrDefault(m => m.StatusID == status.StatusID);

                    if (data != null)
                    {
                        data.StatusName  = status.StatusName;
                        data.UpdatedBy   = "Admin";
                        data.UpdatedDate = DateTime.Now;
                    }
                    _context.Update(data);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StatusExists(status.StatusID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(status));
        }
        public ActionResult Edit(int id, [Bind("TableID,CreatedBy,CreatedDate,IsDeleted,TableName,TableStatus,UpdatedBy,UpdatedDate")] Table table)
        {
            if (id != table.TableID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var data = _context.Table.SingleOrDefault(m => m.TableID == table.TableID);
                    if (table != null)
                    {
                        data.TableName   = table.TableName;
                        data.TableStatus = table.TableStatus;
                        data.UpdatedBy   = "Admin";
                        data.UpdatedDate = DateTime.Now;
                    }
                    _context.Update(data);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TableExists(table.TableID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(table));
        }
Esempio n. 21
0
        public ActionResult Edit(int id, [Bind("CategoryID,CategoryName,CreatedBy,CreatedDate,IsDeleted,UpdatedBy,UpdatedDate")] Category category)
        {
            if (id != category.CategoryID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var data = _context.Category.SingleOrDefault(m => m.CategoryID == category.CategoryID);

                    if (category != null)
                    {
                        data.CategoryName = category.CategoryName;
                        data.UpdatedBy    = "Admin";
                        data.UpdatedDate  = DateTime.Now;
                    }
                    _context.Update(data);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.CategoryID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
        public async Task <IActionResult> Put([FromQuery] int id, [FromQuery] string fagomraade)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }
            using (var context = new dbContext(
                       _serviceProvider.GetRequiredService <
                           DbContextOptions <dbContext> >()))
            {
                var hv = context.Haandvaerkers.Find(id);
                if (hv == null)
                {
                    return(NotFound());
                }

                hv.HVFagomraade = fagomraade;
                context.Update(hv);
                await context.SaveChangesAsync();

                return(Ok("Changed Haandvaerker= " + hv.HVFornavn + ", " + hv.HVFagomraade + ", ID = " + hv.HaandvaerkerId));
            }
        }
Esempio n. 23
0
        public ActionResult Edit(int id, [Bind("BillID,BillDate,CreatedBy,CreatedDate,IsDeleted,OrderID,TotalPrice,UpdatedBy,UpdatedDate")] Bill bill)
        {
            if (id != bill.BillID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var data = _context.Bill.SingleOrDefault(m => m.BillID == bill.BillID);
                    if (bill != null)
                    {
                        data.TotalPrice  = bill.TotalPrice;
                        data.UpdatedBy   = "Admin";
                        data.UpdatedDate = DateTime.Now;
                    }
                    _context.Update(data);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BillExists(bill.BillID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["OrderID"] = new SelectList(_context.Order, "OrderID", "OrderID", bill.OrderID);
            return(View(bill));
        }
Esempio n. 24
0
        public async Task <IActionResult> Update(int id, [FromBody] judge judge)
        {
            if (id <= 0)
            {
                throw new KeyNotFoundException($"Invalid id: {id}.");
            }

            if (id != judge.JudgeID)
            {
                return(NotFound(new { Message = $"Judge id: {id} does not match given data, id: {judge.JudgeID}." }));
            }

            try
            {
                _context.Update(judge);
                await _context.SaveChangesAsync();

                return(Accepted(new { Message = $"Judge record successfully updated id: {id}" }));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(StatusCode(500));
            }
        }