Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ClassroomId,Email,FirstName,LastName,Avartar,Phone,Address,BirthDay,Role,Gender")] Account account)
        {
            if (id != account.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    account.Salt     = PasswordHandle.PasswordHandle.GetInstance().GenerateSalt();
                    account.Password = PasswordHandle.PasswordHandle.GetInstance()
                                       .EncryptPassword(account.Password, account.Salt);
                    _context.Update(account);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountExists(account.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClassroomId"] = new SelectList(_context.Classroom, "Id", "Id", account.ClassroomId);
            return(View(account));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,CreatedAt,UpdateAt")] Subject subject)
        {
            if (id != subject.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(subject);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubjectExists(subject.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(subject));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CreatedAt,UpdatedAt")] Classroom classroom)
        {
            if (id != classroom.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(classroom);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClassroomExists(classroom.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(classroom));
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,AccountId,SubjectId,Theory,Practice,Assignment,Status,CreatedAt,UpdateAt")] Mark mark)
        {
            if (id != mark.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    int   max   = 35;
                    float total = (mark.Theory + mark.Assignment + mark.Practice) * (100 / 100);
                    if (total >= 14)
                    {
                        mark.Status = MarkStatus.Pass;
                    }
                    else
                    {
                        mark.Status = MarkStatus.Fail;
                    }

                    if (mark.Theory == 0 || mark.Assignment == 0 || mark.Practice == 0)
                    {
                        mark.Status = MarkStatus.Fail;
                    }

                    if (mark.Theory == -1 || mark.Assignment == -1 || mark.Practice == -1)
                    {
                        mark.Status = MarkStatus.Null;
                    }

                    _context.Update(mark);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MarkExists(mark.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AccountId"] = new SelectList(_context.Account, "Id", "Id", mark.AccountId);
            ViewData["SubjectId"] = new SelectList(_context.Subject, "Id", "Id", mark.SubjectId);
            return(View(mark));
        }