Example #1
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> Create([Bind("Name,Teacher,Status")] Clazz clazz)
        {
            if (ModelState.IsValid)
            {
                _context.Add(clazz);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(clazz));
        }
 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());
 }
        public async Task <IActionResult> Create([Bind("SubjectId,Name")] Subject subject)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subject);
                await _context.SaveChangesAsync();

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