Esempio n. 1
0
        public async Task <IActionResult> PostLogin([FromBody] Login login)
        {
            var userId = User.FindFirst("sub").Value;

            login.UserId    = userId;
            login.LoginName = login.LoginName.ToLower();
            ModelState.Remove("UserId");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (String.IsNullOrEmpty(userId))
            {
                return(BadRequest("id can not be null"));
            }

            // check db if exist.
            if (await _adContext.Logins.AnyAsync(c => c.LoginName == login.LoginName))
            {
                return(BadRequest("the account already exist."));
            }

            _adContext.Logins.Add(login);
            await _adContext.SaveChangesAsync();

            return(Ok());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutUndertakenInitiatives([FromRoute] Guid id, [FromBody] UndertakenInitiatives undertakenInitiatives)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != undertakenInitiatives.UndertakenInitiativeID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PostTopTenHighestCompensations([FromBody] List <TopTenHighestCompensations> topTenHighestCompensations, [FromRoute] Guid companyProfileID)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.TopTenHighestCompensations.AddRange(topTenHighestCompensations);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTopTenHighestCompensations", new { companyProfileID = companyProfileID }, topTenHighestCompensations));
        }
Esempio n. 4
0
        public async Task <IActionResult> PostLeftLawyers([FromBody] List <LeftLawyers> leftLawyers, [FromRoute] Guid companyProfileID)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.LeftLawyers.AddRange(leftLawyers);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLeftLawyers", new { companyProfileID = companyProfileID }, leftLawyers));
        }
Esempio n. 5
0
        public async Task <IActionResult> PostPromotionsAssociatePartners([FromBody] List <PromotionsAssociatePartners> promotionsAssociatePartners, [FromRoute] Guid companyProfileID)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.PromotionsAssociatePartners.AddRange(promotionsAssociatePartners);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPromotionsAssociatePartners", new { companyProfileID = companyProfileID }, promotionsAssociatePartners));
        }
Esempio n. 6
0
        public async Task <IActionResult> PostCertificates([FromBody] List <Certificates> certificates, [FromRoute] Guid companyProfileID)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Certificates.AddRange(certificates);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCertificates", new { companyProfileID = companyProfileID }, certificates));
        }
Esempio n. 7
0
        public async Task <IActionResult> PostFirmDemographics([FromBody] List <FirmDemographics> firmDemographics, [FromRoute] Guid companyProfileID)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.FirmDemographics.AddRange(firmDemographics);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFirmDemographics", new { companyProfileID = companyProfileID }, firmDemographics));
        }
Esempio n. 8
0
        public async Task <IActionResult> PostFirms([FromBody] Firms firms)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Firms.Add(firms);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFirms", new { id = firms.FirmID }, firms));
        }
Esempio n. 9
0
        public async Task <IActionResult> PostAudit([FromBody] Audit audit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            audit.AuditID      = Guid.NewGuid();
            audit.DateModified = DateTime.Now;

            _context.AuditTrails.Add(audit);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAudit", new { id = audit.AuditID }, audit));
        }
Esempio n. 10
0
        public async Task <IActionResult> updateSUrvey([FromBody] Survey survey)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }

            var companyProfile = await _context.CompanyProfiles.SingleOrDefaultAsync(m => m.CompanyProfileID == survey.CompanyProfile.CompanyProfileID);

            if (companyProfile == null)
            {
                return(null);
            }
            var fd   = firmDemographicsController.GetFirmDemographics(companyProfile.CompanyProfileID);
            var jl   = joinedLawyersController.GetJoinedLawyers(companyProfile.CompanyProfileID);
            var ll   = leftLawyersController.GetLeftLawyers(companyProfile.CompanyProfileID);
            var pap  = promotionsAssociatePartnersController.GetPromotionsAssociatePartners(companyProfile.CompanyProfileID);
            var rhl  = reducedHoursLawyersController.GetReducedHoursLawyers(companyProfile.CompanyProfileID);
            var thc  = topTenHighestCompensationsController.GetTopTenHighestCompensations(companyProfile.CompanyProfileID);
            var cert = certificatesController.GetCertificates(companyProfile.CompanyProfileID);
            var ld   = leadershipDemographicsController.GetLeadershipDemographics(companyProfile.CompanyProfileID);
            var ui   = await undertakenInitiativesController.GetUndertakenInitiatives(companyProfile.CompanyProfileID);

            _context.RemoveRange(fd);
            _context.RemoveRange(jl);
            _context.RemoveRange(ll);
            _context.RemoveRange(pap);
            _context.RemoveRange(rhl);
            _context.RemoveRange(thc);
            _context.RemoveRange(cert);
            _context.RemoveRange(ld);
            _context.Remove(ui);

            await _context.SaveChangesAsync();

            return(Ok(SaveSUrvey(survey)));
        }
Esempio n. 11
0
        public async Task <IActionResult> Get()
        {
            DateTime date            = DateTime.Now;
            var      firstDayOfMonth = new DateTime(date.Year, date.Month, 1);
            var      lastDayOfMonth  = firstDayOfMonth.AddMonths(1);
            var      accts           = await _repo.GetAcctNAsync(firstDayOfMonth, lastDayOfMonth);

            if (accts == null)
            {
                throw new Exception("not accts found");
            }
            var logins = await _adContext.Logins.ToListAsync();

            if (logins == null)
            {
                throw new Exception("not logins found");
            }
            var userInfos = await _repo.GetUserInfosAsync();

            if (userInfos == null)
            {
                throw new Exception("not userInfos found");
            }
            foreach (var u in userInfos)
            {
                var temp_logins = logins.Where(c => c.UserId == u.UserId);
                if (temp_logins.IsNullOrCountEqualsZero())
                {
                    //TODO log user do not have any logins
                    Console.WriteLine("log user do not have any logins");
                    continue;
                }
                var temp_accts = accts.Where(c => temp_logins.Any(l => l.LoginName == c.UserName));
                if (temp_accts.IsNullOrCountEqualsZero())
                {
                    //TODO user do not connection single time.
                    Console.WriteLine("user do not connection single time.");
                    continue;
                }
                var totalIn      = temp_accts.Sum(c => c.TotalInput);
                var totalOut     = temp_accts.Sum(c => c.TotalOutput);
                var totalTraffic = totalIn + totalOut;
                if (totalTraffic > u.MonthlyTraffic)
                {
                    Console.WriteLine($"{totalTraffic} > {u.MonthlyTraffic} = {totalTraffic > u.MonthlyTraffic}");
                    // send command disable all user's logins
                    var lgs = _adContext.Logins.Where(c => c.UserId == u.UserId);
                    foreach (var l in lgs)
                    {
                        l.Enabled = false;
                    }
                    // log it
                }
                else
                {
                    Console.WriteLine($"{totalTraffic} > {u.MonthlyTraffic} = {totalTraffic > u.MonthlyTraffic}");
                    // send command enable all user' logins
                    var lgs = _adContext.Logins.Where(c => c.UserId == u.UserId);
                    foreach (var l in lgs)
                    {
                        l.Enabled = true;
                    }
                    // log it
                }
            }

            foreach (var a in accts)
            {
                var totalTraffic = a.TotalInput + a.TotalOutput;
                //TODO when login can configure max traffic then allow dial in set to false, else enable it.
                var login = logins.FirstOrDefault(c => c.LoginName == a.UserName);
                if (login?.MonthlyTraffic == null)
                {
                    login.AllowDialIn = true;
                }
                else if (totalTraffic > login.MonthlyTraffic)
                {
                    login.AllowDialIn = false;
                }
                else
                {
                    login.AllowDialIn = true;
                }
            }

            await _adContext.SaveChangesAsync();

            return(Ok());
        }