public async Task <IActionResult> Edit(int id, [Bind("Act_typeId,ActivityName")] Act_type act_type)
        {
            if (id != act_type.Act_typeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(act_type);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Act_typeExists(act_type.Act_typeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(act_type));
        }
        public async Task <IActionResult> Create([Bind("Act_typeId,ActivityName")] Act_type act_type)
        {
            if (ModelState.IsValid)
            {
                _context.Add(act_type);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(act_type));
        }
        public async Task <IActionResult> Edit(int?id, byte[] rowVersion)
        {
            if (id == null)
            {
                return(NotFound());
            }


            var dailyActivityToUpdate = await _context.DailyActivities
                                        .Include(d => d.Act_Type)
                                        .Include(d => d.Staff)
                                        .FirstOrDefaultAsync(m => m.DailyActivityId == id);


            if (dailyActivityToUpdate == null)
            {
                DailyActivity deleteDailyActivity = new DailyActivity();
                await TryUpdateModelAsync(deleteDailyActivity);

                ModelState.AddModelError(string.Empty,
                                         "Unable to save changes. The Activity was deleted by another user.");
                ViewData["Act_typeId"] = new SelectList(_context.Act_Types, "Act_typeId", "ActivityName", deleteDailyActivity.Act_typeId);
                ViewData["StaffId"]    = new SelectList(_context.Staffs, "StaffId", "FirstName", deleteDailyActivity.StaffId);
                return(View(deleteDailyActivity));
            }

            _context.Entry(dailyActivityToUpdate).Property("RowVersion").OriginalValue = rowVersion;

            if (await TryUpdateModelAsync <DailyActivity>(
                    dailyActivityToUpdate,
                    "",
                    s => s.DateStart, s => s.DateEnd, s => s.Act_typeId, s => s.StaffId))
            {
                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var exceptionEntry = ex.Entries.Single();
                    var clientValues   = (DailyActivity)exceptionEntry.Entity;
                    var databaseEntry  = exceptionEntry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        ModelState.AddModelError(string.Empty,
                                                 "Unable to save changes. The Daily Activity was deleted by another user.");
                    }
                    else
                    {
                        var databaseValues = (DailyActivity)databaseEntry.ToObject();

                        if (databaseValues.DateStart != clientValues.DateStart)
                        {
                            ModelState.AddModelError("DateStart", $"Current value: {databaseValues.DateStart:d}");
                        }
                        if (databaseValues.DateEnd != clientValues.DateEnd)
                        {
                            ModelState.AddModelError("DateEnd", $"Current value: {databaseValues.DateEnd:t}");
                        }
                        if (databaseValues.Act_typeId != clientValues.Act_typeId)
                        {
                            Act_type databaseAct_type = await _context.Act_Types.FirstOrDefaultAsync(i => i.Act_typeId == databaseValues.Act_typeId);

                            ModelState.AddModelError("Act_typeId", $"Current value: {databaseAct_type.ActivityName}");
                        }
                        if (databaseValues.StaffId != clientValues.StaffId)
                        {
                            Staff databaseStaff = await _context.Staffs.FirstOrDefaultAsync(i => i.StaffId == databaseValues.StaffId);

                            ModelState.AddModelError("StaffId", $"Current value: {databaseStaff.FirstName}");
                        }

                        ModelState.AddModelError(string.Empty, "Record is modified by another user. "
                                                 + " Records is not updated yet. "
                                                 + " To cancel update close this windows or click back to list "
                                                 + " To update press save again");
                        dailyActivityToUpdate.RowVersion = (byte[])databaseValues.RowVersion;
                        ModelState.Remove("RowVersion");
                    }
                }
            }
            ViewData["Act_typeId"] = new SelectList(_context.Act_Types, "Act_typeId", "ActivityName", dailyActivityToUpdate.Act_typeId);
            ViewData["StaffId"]    = new SelectList(_context.Staffs, "StaffId", "FirstName", dailyActivityToUpdate.StaffId);
            return(View(dailyActivityToUpdate));
        }