コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,FireDate,HireDate,FireReason,EmployeeId")] OldWorkPlace oldWorkPlace)
        {
            if (id != oldWorkPlace.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(oldWorkPlace);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OldWorkPlaceExists(oldWorkPlace.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", "Employees"));
            }
            return(View(oldWorkPlace));
        }
コード例 #2
0
        public async Task <IActionResult> AddOldWorkPlaces(OldWorkPlaceModel oldWorkPlace)
        {
            if (ModelState.IsValid)
            {
                if (oldWorkPlace == null)
                {
                    ModelState.AddModelError("", "Something went wrong");
                    return(RedirectToAction("AddOldWorkPlaces", "Employee"));
                }
                else
                {
                    OldWorkPlace owp = new OldWorkPlace
                    {
                        WorkPlaceName = oldWorkPlace.WorkPlaceName,
                        EmployeeId    = oldWorkPlace.IdEmployee,
                        FireDate      = oldWorkPlace.FireDate,
                        FireReason    = oldWorkPlace.FireReason,
                        HireDate      = oldWorkPlace.HireDate
                    };
                    dbContext.OldWorkPlace.Add(owp);
                    await dbContext.SaveChangesAsync();

                    return(RedirectToAction("Details", "Employee", new { id = oldWorkPlace.IdEmployee }));
                }
            }
            return(View());
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind
                                                      (include: "Name, FireDate, HireDate, FireReason, EmployeeId")] OldWorkPlace oldWorkPlace)
        {
            if (ModelState.IsValid)
            {
                _context.Add(oldWorkPlace);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Employees"));
            }

            return(View(oldWorkPlace));
        }
コード例 #4
0
        public async Task <ActionResult> AddEmployeeOldWorkPlace(OldWorkPlace oldWork)
        {
            if (ModelState.IsValid)
            {
                var data = HttpContext.Session.GetObjectFromJson <Employee>("Employ");

                dbContext.OldWorkPlaces.Add(new OldWorkPlace
                {
                    WorkCompany  = oldWork.WorkCompany,
                    WorkPosition = oldWork.WorkPosition,
                    StarDate     = oldWork.StarDate,
                    EndDate      = oldWork.EndDate,
                    WorkStatus   = oldWork.WorkStatus,
                    EmployeeId   = data.Id
                });

                await dbContext.SaveChangesAsync();

                ModelState.AddModelError("", "Success");
            }
            return(View());
        }
コード例 #5
0
        public async Task <ActionResult> EditOldWork(OldWorkPlace workPlace)
        {
            if (ModelState.IsValid)
            {
                var oldworkId = HttpContext.Session.GetObjectFromJson <OldWorkPlace>("oldwork").Id;
                var oldwork   = await dbContext.OldWorkPlaces.Where(x => x.Id == oldworkId).FirstOrDefaultAsync();

                if (oldwork != null)
                {
                    oldwork.WorkCompany  = workPlace.WorkCompany;
                    oldwork.WorkPosition = workPlace.WorkPosition;
                    oldwork.WorkStatus   = workPlace.WorkStatus;
                    oldwork.StarDate     = workPlace.StarDate;
                    oldwork.EndDate      = workPlace.EndDate;

                    dbContext.Update <OldWorkPlace>(oldwork);
                    await dbContext.SaveChangesAsync();

                    return(View(oldwork));
                }
                return(RedirectToAction("AboutEmployee", "Employee", new { area = "Admin" }));
            }
            return(View());
        }