Пример #1
0
        public AdminEntity UpdateAdmin(int adminId, AdminData adminData)
        {
            var admin = GetAdmin(adminId);

            if (adminData.Email != null)
            {
                admin.Email = adminData.Email;
            }
            if (adminData.Password != null)
            {
                admin.PasswordHash = Crypto.Sha256(adminData.Password);
            }
            if (adminData.Info != null)
            {
                admin.Info = adminData.Info;
            }

            _context.SaveChanges();
            return(admin);
        }
Пример #2
0
        public AdminEntity CreateAdmin(AdminData adminData)
        {
            var admin     = new AdminEntity();
            var adminInfo = new { registered = DateTime.UtcNow };

            if (new[] { adminData.Email, adminData.Info, adminData.Password }.Any(entry => entry == null))
            {
                throw new Exception("Important properties were not filled!");
            }
            admin.Email        = adminData.Email;
            admin.PasswordHash = Crypto.Sha256(adminData.Password);

            var adminI = JObject.Parse(adminData.Info);

            adminI["registered"] = DateTime.UtcNow;
            admin.Info           = adminI.ToJson();

            //admin.Info = JsonConvert.SerializeObject(adminInfo);


            _context.Add(admin);
            _context.SaveChanges();
            return(admin);
        }
Пример #3
0
        public AdminEntity Register(AdminData data)
        {
            var adminLogic = new AdminLogic(_context);

            return(adminLogic.CreateAdmin(data));
        }