Exemplo n.º 1
0
        public async Task <IActionResult> Store(Project project)
        {
            project.UserId = (Guid)AuthenticateUserId;

            var notification = NduModel <Project> .Validate(project);

            if (!notification.Success())
            {
                return(BadRequest(notification.GetNotifications()));
            }

            _context.Entry(project).State = project.Id == Guid.Empty ? EntityState.Added : EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Ok(project));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Store(TasklyNetShared.Models.Task task)
        {
            if (task == null)
            {
                return(NotFound());
            }

            task.UserId = (Guid)AuthenticateUserId;

            var notification = NduModel <TasklyNetShared.Models.Task> .Validate(task);

            if (!notification.Success())
            {
                return(BadRequest(notification.GetNotifications()));
            }

            _context.Entry(task).State = task.Id == Guid.Empty ? EntityState.Added : EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Ok(task));
        }
        public async Task <NduNotification> Execute(AccountCreateRequest request)
        {
            var result = new NduNotification();

            var userAccountExists = await _context.Users
                                    .AnyAsync(m => m.Email == request.Email);

            if (userAccountExists)
            {
                result.AddNotification("Email", "User already exists");
                return(result);
            }

            if (request.Password != request.ConfirmPassword)
            {
                result.AddNotification("Password not match");
                return(result);
            }

            var crypto = new NduCrypto(Settings.CRYPTO_KEY);

            var passwordEncrypted = crypto.Encrypt(request.Password);

            var user = new User()
            {
                Email    = request.Email,
                Name     = request.Name,
                Password = passwordEncrypted
            };

            result = NduModel <User> .Validate(user);

            if (result.Success())
            {
                _context.Entry(user).State = EntityState.Added;
                await _context.SaveChangesAsync();
            }

            return(result);
        }