public async Task <IActionResult> Delete(long id)
        {
            _logger.LogDebug($"Deleting user with id {id}");

            var user = await _dbContext.Users.FindAsync(id);

            if (user == null)
            {
                return(NotFound());
            }

            _dbContext.Users.Remove(user);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Delete(long id)
        {
            _logger.LogDebug($"Deleting time entries with id {id}");

            var timeEntry = await _dbContext.TimeEntries.FindAsync(id);

            if (timeEntry == null)
            {
                return(NotFound());
            }

            _dbContext.TimeEntries.Remove(timeEntry);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Delete(long id)
        {
            _logger.LogDebug($"Deleting project with id {id}");

            var project = await _dbContext.Projects.FindAsync(id);

            if (project == null)
            {
                return(NotFound());
            }

            _dbContext.Projects.Remove(project);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 4
0
        // delete, not returning anything (ne treba preko get)
        public async Task <IActionResult> Delete(long id)
        {
            _logger.LogInformation($"Deleting user with id: {id}");

            var user = await _dbContext.Users.FindAsync(id);

            if (user == null)
            {
                _logger.LogWarning($"No user found with id: {id}");
                return(NotFound());
            }

            _dbContext.Users.Remove(user);          // samo markira user-a za brisanje
            await _dbContext.SaveChangesAsync();    // unit of work

            return(Ok());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Delete(long id)
        {
            _logger.LogInformation($"Deleting user with id: {id}");

            var user = await _dbContext.Users.FindAsync(id);

            if (user == null)
            {
                _logger.LogWarning($"No user found with id {id}");
                return(NotFound());
            }

            _dbContext.Users.Remove(user);
            await _dbContext.SaveChangesAsync(); //Tek sada izmijeni sve u bazi, do sada je samo u kodu

            return(Ok());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Delete(long id)
        {
            _logger.LogInformation(message: $"Deleting user with id {id}");

            var user = await _dbContext.Users.FindAsync(id);

            if (user == null)
            {
                _logger.LogWarning(message: $"No user found with id {id}");
                return(NotFound());
            }

            _dbContext.Users.Remove(user);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 7
0
        public async Task <User> FindOrCreateSlackUser(string slackUserId, string slackUsername)
        {
            Guard.ThrowIfCheckFails(!string.IsNullOrEmpty(slackUserId), "cannot be null or empty", nameof(slackUserId));
            Guard.ThrowIfCheckFails(!string.IsNullOrEmpty(slackUsername), "cannot be null or empty", nameof(slackUsername));

            var user = await db.Users.FirstOrDefaultAsync(
                x => x.SlackUserId.Equals(slackUserId, StringComparison.InvariantCultureIgnoreCase));

            if (user == null)
            {
                user = new User()
                {
                    SlackUserId = slackUserId,
                    UserId      = Guid.NewGuid(),
                    UserName    = slackUsername
                };
                db.Users.Add(user);
                await db.SaveChangesAsync();
            }
            return(user);
        }
Ejemplo n.º 8
0
        private async Task StoreTimeEntryOnFirstDayOfMonth(TimeEntryTypeEnum entryType, User user, int hours, int month)
        {
            var timeEntry = new TimeEntry
            {
                Hours         = hours,
                Date          = new DateTime(DateTime.UtcNow.Year, month, 1),
                TimeEntryType = entryType,
                User          = user
            };

            database.TimeEntries.Add(timeEntry);
            await database.SaveChangesAsync();
        }
Ejemplo n.º 9
0
 public static Task <int> AddAutonomicAsBillingClientAndProject(this TimeTrackerDbContext db)
 {
     db.Database.EnsureCreated();
     db.BillingClients.Add(new BillingClient()
     {
         BillingClientId = 1,
         Name            = "Autonomic"
     });
     db.Projects.Add(new Project()
     {
         ProjectId       = 1,
         BillingClientId = 1,
         Name            = "au"
     });
     return(db.SaveChangesAsync());
 }
Ejemplo n.º 10
0
 public async Task Commit()
 {
     await Dbcontext.SaveChangesAsync();
 }