Example #1
0
        public async Task <IActionResult> PutWorker([FromRoute] int id, [FromBody] Worker worker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != worker.Id)
            {
                return(BadRequest());
            }

            _context.Entry(worker).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> ClientCreate([Bind("WorkerCommentID,Name,Comment,StarRating,LastUpdated,WorkerID")] WorkerComment workerComment)
        {
            if (ModelState.IsValid)
            {
                Worker worker = _context.Worker.Where(m => m.ID == workerComment.WorkerID).FirstOrDefault();
                workerComment.LastUpdated = DateTime.UtcNow.ToLocalTime();
                workerComment.Worker      = worker;

                IdentityUser currUser = await _userManager.GetUserAsync(HttpContext.User);

                workerComment.Name = currUser.UserName;

                _context.Add(workerComment);
                await _context.SaveChangesAsync();

                return(RedirectToAction("ShowComments", new { id = worker.ID }));
            }

            IdentityUser user = await _userManager.GetUserAsync(HttpContext.User);

            ViewData["Username"] = user.UserName;
            ViewDataSelectOneWorker(workerComment.WorkerID);

            return(View(workerComment));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Email,Phone,Gender,Specialization,Created")] Worker worker)
        {
            if (ModelState.IsValid)
            {
                _context.Add(worker);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(worker));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("ID,Job,Name,Services")] Worker worker)
        {
            if (ModelState.IsValid)
            {
                _context.Add(worker);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(worker));
        }
        public async Task <IActionResult> Create([Bind("supervisiorID,first_name,last_name,department")] Supervisior supervisior)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supervisior);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supervisior));
        }
        public async Task <IActionResult> Create([Bind("PositionID,Name,Amount")] Position position)
        {
            if (ModelState.IsValid)
            {
                _context.Add(position);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(position));
        }
Example #7
0
        public async Task <IActionResult> Create([Bind("workerID,first_name,last_name,hired_date,SupervisiorFK")] Worker worker)
        {
            if (ModelState.IsValid)
            {
                _context.Add(worker);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SupervisiorFK"] = new SelectList(_context.Supervisiors, "supervisiorID", "supervisiorID", worker.SupervisiorFK);
            return(View(worker));
        }
        public async Task <IActionResult> Create([Bind("SalaryID,WorkerID,PositionID,Bonus")] Salary salary)
        {
            if (ModelState.IsValid)
            {
                _context.Add(salary);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PositionID"] = new SelectList(_context.Positions, "PositionID", "PositionID", salary.PositionID);
            ViewData["WorkerID"]   = new SelectList(_context.Workers, "ID", "ID", salary.WorkerID);
            return(View(salary));
        }
Example #9
0
        private async Task <WorkerContext> prepareDb()
        {
            var options = new DbContextOptionsBuilder <WorkerContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var workerContext = new WorkerContext(options);

            workerContext.Database.EnsureCreated();


            if (await workerContext.Positions.CountAsync() <= 0)
            {
                for (int i = 1; i <= 10; i++)
                {
                    workerContext.Positions.Add(new Workers.Models.Position()
                    {
                        Name       = "Sprzatacz",
                        PositionID = i,
                        Amount     = 2000
                    });
                    await workerContext.SaveChangesAsync();
                }
            }


            return(workerContext);
        }
Example #10
0
        /*
         *
         * [Test]
         * public async Task PositionControllerTest()
         * {
         *  var dbContext = await prepareDb();
         *  var positionController = new PositionsController(dbContext);
         *
         *  var positions = await positionController.Index();
         *
         *  Assert.NotNull(positions);
         * }
         */

        private async Task <WorkerContext> prepareDb()
        {
            var options = new DbContextOptionsBuilder <WorkerContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var workerContext = new WorkerContext(options);

            workerContext.Database.EnsureCreated();
            if (await workerContext.Workers.CountAsync() <= 0)
            {
                for (int i = 1; i <= 10; i++)
                {
                    workerContext.Workers.Add(new Workers.Models.Worker()
                    {
                        FirstName = "Tomasz",
                        LastName  = "Zwierzynski",
                        Birthday  = DateTime.Parse("1994-08-16")
                    });
                    await workerContext.SaveChangesAsync();
                }
            }

            /*
             * if (await workerContext.Positions.CountAsync() <= 0)
             * {
             *  for (int i = 1; i <= 10; i++)
             *  {
             *      workerContext.Positions.Add(new Workers.Models.Position()
             *      {
             *          Name = "Sprzatacz",
             *          PositionID = 1001,
             *          Amount = 2000
             *      });
             *      await workerContext.SaveChangesAsync();
             *  }
             * }
             */

            return(workerContext);
        }
Example #11
0
        public async Task CreateInBulk(IEnumerable <TEntity> entities)
        {
            await _dbContext.Set <TEntity>().AddRangeAsync(entities);

            await _dbContext.SaveChangesAsync();
        }
        public async Task <int> UpdateToken(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                TimeSpan start_interval  = new TimeSpan(_conf.GetValue <int>("ATU_INTERVAL_START_HOUR"), _conf.GetValue <int>("ATU_INTERVAL_START_MIN"), 0);
                TimeSpan end_interval    = new TimeSpan(_conf.GetValue <int>("ATU_INTERVAL_STOP_HOUR"), _conf.GetValue <int>("ATU_INTERVAL_STOP_MIN"), 0);
                int      REPEAT_INTERVAL = _conf.GetValue <int>("ATU_SERIVCE_REPEAT_INTERVAL");

                if (_conf.GetValue <bool>("ATU_SERVICE"))
                {
                    try
                    {
                        using (IServiceScope scope = _serviceScopeFactory.CreateScope())
                        {
                            WorkerContext _context = scope.ServiceProvider.GetRequiredService <WorkerContext>();
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Thursday && DateTime.Now.TimeOfDay <= end_interval && DateTime.Now.TimeOfDay >= start_interval)
                            {
                                StakeholderApis stakeholderApis = await _context.StakeholderApis.
                                                                  Where(a => a.StakeholderId == (int)StakeholderIDs.ARD_ID)
                                                                  .SingleOrDefaultAsync();

                                if (stakeholderApis != null && ((stakeholderApis.LastUpdateTime.Value.TimeOfDay > end_interval || stakeholderApis.LastUpdateTime.Value.TimeOfDay < start_interval) || stakeholderApis.LastUpdateTime == null))
                                {
                                    string UserName = stakeholderApis.UserName;
                                    string Password = EncryptionHelper.Decrypt(stakeholderApis.Password);

                                    // Uncomment
                                    UserLoginDto credentials = _ardAccountService.Authenticate(new UserLoginDto()
                                    {
                                        Username = UserName,
                                        Password = Password
                                    });


                                    //Delete
                                    //UserLoginDto credentials = new UserLoginDto()
                                    //{

                                    //    Username = "******",
                                    //    Password = "******",
                                    //    Token = "Test"
                                    //};


                                    if (!string.IsNullOrEmpty(credentials.Token))
                                    {
                                        stakeholderApis.Token          = credentials.Token;
                                        stakeholderApis.LastUpdateTime = DateTime.Now;


                                        await _context.SaveChangesAsync();
                                    }
                                }
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                    }
                }
                await Task.Delay(REPEAT_INTERVAL, cancellationToken);
            }

            return(0);
        }
Example #13
0
        public async Task Sync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                int    REPEAT_INTERVAL = _conf.GetValue <int>("ARS_SERIVCE_REPEAT_INTERVAL");
                string BASE_URL        = _conf.GetValue <string>("API_BASE_URL");
                string AUTH_TOKEN      = _conf.GetValue <string>("AUTH_TOKEN");
                HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
                int syncIdInCurrentLoop = 0;

                if (_conf.GetValue <bool>("ARS_SERVICE"))
                {
                    var scope = _serviceScopeFactory.CreateScope();

                    try
                    {
                        WorkerContext context = scope.ServiceProvider.GetRequiredService <WorkerContext>();


                        List <TblApiSync> failedRecords = await context.TblApiSync.Where(a => a.SyncStatus == false && a.TryCount <= 4).ToListAsync();

                        if (failedRecords.Any())
                        {
                            failedRecords.ForEach(async s =>
                            {
                                syncIdInCurrentLoop       = s.ApiSynId;
                                TblApiSync toUpdateRecord = await context.TblApiSync.Where(r => r.ApiSynId == s.ApiSynId).SingleOrDefaultAsync();

                                try
                                {
                                    httpResponseMessage = await _apiClientServices.GetAsync(new StringBuilder(BASE_URL).Append(s.EndPoint).ToString(),
                                                                                            AUTH_TOKEN, s.Parameter);

                                    if (httpResponseMessage.StatusCode == HttpStatusCode.OK || httpResponseMessage.StatusCode == HttpStatusCode.Created)
                                    {
                                        toUpdateRecord.SyncStatus = true;
                                    }
                                    else
                                    {
                                        toUpdateRecord.TryCount    = s.TryCount + 1;
                                        toUpdateRecord.UpdatedDate = DateTime.Now;
                                    }

                                    await context.SaveChangesAsync();
                                }
                                catch (Exception ex)
                                {
                                    toUpdateRecord.SyncStatus  = false;
                                    toUpdateRecord.TryCount    = toUpdateRecord.TryCount + 1;
                                    toUpdateRecord.UpdatedDate = DateTime.Now;
                                    await context.SaveChangesAsync();
                                }
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                // The sync operation will repeat after recieving value of settings.
                await Task.Delay(REPEAT_INTERVAL, stoppingToken);
            }
        }
Example #14
0
 public async Task AddAsyn(TEntity item)
 {
     _dbSet.Add(item);
     await _context.SaveChangesAsync();
 }