Ejemplo n.º 1
0
        public async Task <ActionResult> DeleteConfirmed(Guid id)
        {
            Job job = await db.Jobs.FindAsync(id);

            db.Jobs.Remove(job);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Create([Bind(Exclude = "UserId,ApiKey")] ServiceUser serviceUser)
        {
            ServiceUser user = await _context.ServiceUsers.SingleOrDefaultAsync(u => u.EmailAddress.Equals(serviceUser.EmailAddress.Trim(), StringComparison.InvariantCultureIgnoreCase));

            if (user != null)
            {
                ModelState.AddModelError("EmailAddress", "Email already exists! Please use another email address.");
            }
            serviceUser.UserId = Guid.NewGuid();
            serviceUser.ApiKey = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString());
            TryUpdateModel(serviceUser);
            if (ModelState.IsValid || serviceUser.ApiKey != null)
            {
                serviceUser.Password = Encrypt.CreateHash(serviceUser.Password);
                _context.ServiceUsers.Add(serviceUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = serviceUser.UserId }));
            }

            return(View(serviceUser));
        }