Exemple #1
0
        public HelpRequestResponse CreateClientHelpRequestResponse(HelpRequestResponseCreateModel vm)
        {
            var helpRequest = _context.HelpRequests
                              .Where(x => x.Id == vm.HelpRequestId)
                              .FirstOrDefault();

            var oldClientHelpRequest = _context.HelpRequestsResponses.Where(x => x.HelpRequest.ClientId == helpRequest.ClientId).ToList();


            oldClientHelpRequest.ForEach(x => x.IsActive = false);

            var newHelpRequest = new HelpRequestResponse
            {
                HelpIncomingDateTimeUtc = vm.ExpirationDateUtc,
                HelpRequestId           = vm.HelpRequestId,
                HelpRequestState        = vm.HelpRequestState,
                IsActive         = true,
                LanguageId       = vm.LanguageId,
                ShortInstruction = vm.ShortInstruction
            };

            _context.HelpRequestsResponses.Add(newHelpRequest);
            _context.SaveChanges();

            return(newHelpRequest);
        }
        public async Task GenerateAndSendTokenAsync(Client client)
        {
            var clientToken =
                context.ClientTokens
                .FirstOrDefault(x => x.ClientId.Equals(client.ClientId) && !x.IsUsed && x.ValidUntil > DateTime.UtcNow);

            if (clientToken == null)
            {
                clientToken = new ClientToken
                {
                    ClientId   = client.ClientId,
                    Token      = GenerateRandomToken(),
                    ValidUntil = DateTime.UtcNow.AddMinutes(5),
                    IsUsed     = false
                };

                context.ClientTokens.Add(clientToken);
                context.SaveChanges();
            }

            var model = new PasswordResetCodeEmailModel
            {
                Code      = clientToken.Token,
                FirstName = client.FirstName,
                LastName  = client.LastName
            };

            await emailService.SendTemplateEmail(client.Email, Resource.PasswordResetTokenEmailSubject, "ResetPasswordCodeEmail", model);

            //await emailService.Send(client.UserLoginData.Email, , clientToken.Token);
        }
Exemple #3
0
        public void Create(Maintenance maintenance)
        {
            if (maintenance == null)
            {
                throw new ArgumentNullException(nameof(maintenance));
            }

            _context.Maintenances.Add(maintenance);
            _context.SaveChanges();
        }
Exemple #4
0
        public void CreateConfiguration(ClientConfigurationGroup clientConfigurationGroup)
        {
            if (clientConfigurationGroup == null)
            {
                throw new ArgumentNullException(nameof(clientConfigurationGroup));
            }

            _context.ClientConfigurationGroup.Add(clientConfigurationGroup);
            _context.SaveChanges();
        }
        public async Task <IHttpActionResult> CreateAdminAccount([FromBody] AdminAccountCreateViewModel adminAccount)
        {
            if (!ModelState.IsValid)
            {
                return(Content(HttpStatusCode.BadRequest, GetValidationErrors()));
            }

            if (_applicationUserManager.FindByName(adminAccount.UserName) != null)
            {
                ModelState.AddModelError("RegisterError", Resources.Resource.UserAccountExists);
            }

            if (!ModelState.IsValid)
            {
                return(Content(HttpStatusCode.BadRequest, GetValidationErrors()));
            }

            IdentityRole adminRole = _roleService.GetAdminRole();

            var currentAdminGroup = _userService.GetMaintenanceSettingsId();

            var user = new UserLoginData
            {
                UserName       = adminAccount.UserName,
                IsActive       = true,
                OriginUsername = adminAccount.UserName
            };

            var admin = new Admin
            {
                FirstName     = adminAccount.FirstName,
                LastName      = adminAccount.LastName,
                MaintenanceId = currentAdminGroup
            };
            var password         = System.Web.Security.Membership.GeneratePassword(10, 4);
            var userCreateResult = _applicationUserManager.Create(user, password);
            var roleCreateResult = _applicationUserManager.AddToRole(user.Id, adminRole.Name);

            admin.AdminId = user.Id;
            _context.Admin.Add(admin);
            _context.SaveChanges();
            _loggerService.Log(UserId, ActionType.Create, $"Admin account created - {user.UserName}");

            try
            {
                await _emailService.Send(adminAccount.Email, "Account created", $"Username: {adminAccount.UserName} Password:{password}");

                return(Created("/api/admin/" + user.Id, user.Id));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
Exemple #6
0
        public bool ChangeClientStatus(string clientId)
        {
            var userLoginData = _context.Users.Find(clientId);

            if (userLoginData == null)
            {
                return(false);
            }

            userLoginData.IsActive = !userLoginData.IsActive;

            _context.SaveChanges();
            return(true);
        }
        public HelpRequestsDetailsModel AddNewRequest(HelpRequestCreateModel model, string clientId)
        {
            var m = new HelpRequest
            {
                IsSolved            = false,
                ClientId            = clientId,
                HelpRequestCategory = model.HelpRequestCategory,
                RequestDate         = DateTime.UtcNow,
                Longitude           = model.Longitude,
                Langitude           = model.Latitude
            };

            _context.HelpRequests.Add(m);

            _context.SaveChanges();

            return(GetById(m.Id));
        }
        public void Log(string userId, ActionType action, string description)
        {
            dbContext.UserAudit.Add(new UserAudit
            {
                ActionType  = GetActionDescription(action),
                AdminId     = userId,
                DateTime    = DateTime.UtcNow,
                Description = description
            });

            dbContext.SaveChanges();
        }
Exemple #9
0
        public void RemoveToken(string id)
        {
            var token = context.RefreshTokens
                        .Where(x => x.Id == id).FirstOrDefault();

            if (token == null)
            {
                return;
            }

            var tokens = context
                         .RefreshTokens
                         .Where(x => x.OAuthClientId == token.OAuthClientId && x.UserId == token.UserId);

            context.RefreshTokens.RemoveRange(tokens);
            context.SaveChanges();
        }
Exemple #10
0
        public Language GetDefaultLanguage()
        {
            var defaultCode = ConfigurationManager.AppSettings["LanguageDefaultCode"];
            var defaultName = ConfigurationManager.AppSettings["LanguageDefaultName"];

            var result = _context.Language.FirstOrDefault(x => x.LanguageCode.Equals(defaultCode));

            if (result == null)
            {
                Language l = new Language
                {
                    LanguageCode = defaultCode,
                    LanguageName = defaultName
                };
                _context.Language.Add(l);
                _context.SaveChanges();

                return(l);
            }
            else
            {
                return(result);
            }
        }
 public void Create(EmergencyContactNumbers emergencyContactNumbers)
 {
     _context.EmergencyContactNumbers.Add(emergencyContactNumbers);
     _context.SaveChanges();
 }