public IActionResult CreateAccount([FromBody] GeneralInformationWithRoles generalInfoWithRoles, [FromHeader] string Authorization, [FromHeader] string Role)
 {
     if (CheckToken(Authorization) == true && CheckPermission(Role) == true)
     {
         if (ModelState.IsValid)
         {
             Account account = new Account();
             account.GeneralInformation = generalInfoWithRoles.GeneralInformation;
             foreach (var id in generalInfoWithRoles.RoleIds)
             {
                 var         role        = _context.Role.Find(id);
                 RoleAccount roleAccount = new RoleAccount
                 {
                     Role    = role,
                     Account = account
                 };
                 _context.Add(roleAccount);
             }
             _context.Add(account);
             _context.Add(account.GeneralInformation);
             _context.SaveChanges();
             account.RollNumber = "B19APTECH" + account.AccountId.ToString("D4");
             account.Password   = account.GeneralInformation.Dob.ToString("ddMMyy");
             account.EncryptPassword(account.Password);
             _context.Update(account);
             _context.SaveChanges();
             return(new JsonResult(account.GeneralInformation.Dob.ToString("ddMMyy")));
         }
         //return new JsonResult(generalInfoWithRoles);
     }
     return(Unauthorized());
 }
Пример #2
0
        public async Task <IActionResult> Create([Bind("GeneralInformation")] Account account, int[] roleIds)
        {
            if (ModelState.IsValid)
            {
                foreach (var id in roleIds)
                {
                    var         role        = _context.Role.Find(id);
                    RoleAccount roleAccount = new RoleAccount
                    {
                        Role    = role,
                        Account = account
                    };
                    _context.Add(roleAccount);
                }
                _context.Add(account);
                _context.Add(account.GeneralInformation);
                await _context.SaveChangesAsync();

                account.RollNumber = "B19APTECH" + account.AccountId.ToString("D4");
                account.Password   = account.GeneralInformation.Dob.ToString();
                account.EncryptPassword(account.Password);
                _context.Update(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
        public async Task <IActionResult> Edit(int id, [Bind("SubjectId,Name")] Subject subject)
        {
            if (id != subject.SubjectId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(subject);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubjectExists(subject.SubjectId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(subject));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Name,Teacher,Status")] Clazz clazz)
        {
            if (id != clazz.ClazzId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(clazz);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClazzExists(clazz.ClazzId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(clazz));
        }