Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ProjectId,Name,Start,Deadline,Budget,Deposit,Status")] Projects projects)
        {
            if (id != projects.ProjectId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(projects);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProjectsExists(projects.ProjectId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(projects));
        }
Пример #2
0
        public void Edit(Library.Model.Location model)
        {
            IQueryable <Location> locations = _locationContext.Locations
                                              .Include(l => l.InventoryLines)
                                              .ThenInclude(il => il.Product);
            Location entity = locations.First(l => l.LocationId == model.LocationId);

            if (entity == null)
            {
                s_logger.Warn($"Location to be edited does not exist: ignoring.");
                return;
            }
            foreach (Library.Model.InventoryLine line in model.Inventory)
            {
                InventoryLine entity2 = entity.InventoryLines.First(il => il.InventoryLineId == line.InventoryLineId);
                if (entity2 == null)
                {
                    s_logger.Warn($"InventoryLine to be edited on location ${entity.LocationId} does not exist: ignoring.");
                    return;
                }
            }

            s_logger.Info($"Editing Location");

            var products = _locationContext.Products
                           .AsNoTracking();

            foreach (Library.Model.InventoryLine line in model.Inventory)
            {
                InventoryLine entity2 = entity.InventoryLines.First(il => il.InventoryLineId == line.InventoryLineId);
                entity2.Quantity  = line.Quantity;
                entity2.LineTotal = entity2.Quantity * entity2.Product.UnitPrice;
                _locationContext.Update(entity2);
            }
            _locationContext.Update(entity);
        }
Пример #3
0
        public async Task <IActionResult> ChangePassword(UserWithNewPassword user)
        {
            if (ModelState.IsValid)
            {
                var currentUser = await _context.User.FirstAsync();

                if (currentUser.Login == user.Login && currentUser.Password == Encrypt(user.Password))
                {
                    try
                    {
                        currentUser.Password = Encrypt(user.NewPassword);

                        _context.Update(currentUser);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                    return(RedirectToAction("SignIn", "Login"));
                }
            }
            return(View(user));
        }
Пример #4
0
        public async Task <IActionResult> AddorEdit(int Id,
                                                    [Bind("Id,Name,Language,Info,StartDate,EndDate,ProjectDataId,ReportJournalId")]
                                                    ProjectViewModel project)
        {
            if (ModelState.IsValid)
            {
                if (project.Id == 0)
                {
                    var userId = _userManager.GetUserId(this.HttpContext.User);
                    project.ProjectUserId = userId;

                    var projects = await _context.ProjectViewModel.Where(x => x.ProjectUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    var allChartData = await _context.ChartData.Where(x => x.ChartUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    var langTypes = projects.GroupBy(x => x.Language).ToList();

                    foreach (var c in allChartData)
                    {
                        if (userId == c.ChartUserId)
                        {
                            project.ProjectDataId = c.Id;

                            _context.Add(project);
                            _context.Update(c);
                            c.DataForProjects.Add(project);

                            await _context.SaveChangesAsync();

                            TempData["Message"] = "Project Created!";
                            return(View(project));
                        }

                        else
                        {
                            project.ProjectUserId = userId;

                            var newChartData = new ChartData
                            {
                                ChartUserId = userId
                            };

                            _context.Add(project);
                            _context.Add(newChartData);
                            project.ProjectDataId = newChartData.Id;
                            newChartData.DataForProjects.Add(project);
                            await _context.SaveChangesAsync();

                            TempData["Message"] = "Project Created!";
                            return(View(project));
                        }
                    }
                }

                else
                {
                    var userId          = _userManager.GetUserId(this.HttpContext.User);
                    var currentProjects = await _context.ProjectViewModel.Where(x => x.ProjectUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    var allCurrentChartData = await _context.ChartData.Where(x => x.ChartUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    foreach (var c in allCurrentChartData)
                    {
                        _context.Update(project);
                        _context.Update(c);
                        await _context.SaveChangesAsync();

                        TempData["Message"] = "Project Updated!";
                        return(View(project));
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            else
            {
                TempData["Message"] = "Please try again.";
                return(RedirectToAction(nameof(AddorEdit)));
            }
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, [Bind("EmployeeId,FirstName,LastName,Birthday,PhoneNumber,Position,Salary,Experiance,BeginningOfWork,CalculateMonthPaymentFrom,Image,Description")] Employees employees)
        {
            if (id != employees.EmployeeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    UploadPhoto(employees);
                    _context.Update(employees);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeesExists(employees.EmployeeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(employees));
        }