Esempio n. 1
0
        public async Task <IActionResult> AddOfficer(OfficerDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            User user = await _userManager.FindByEmailAsync(model.UserName);

            if (user != null)
            {
                return(BadRequest(ModelState));
            }

            var now = DateTime.Now;

            user = new User()
            {
                SecurityStamp    = Guid.NewGuid().ToString(),
                UserName         = model.UserName,
                CreatedDate      = now,
                LastModifiedDate = now
            };
            Random rnd      = new Random();
            int    num      = rnd.Next(1, 9);
            string password = PinGenerator.RandomString(4) + "@" + num;
            var    result   = await _userManager.CreateAsync(user, password);

            await _userManager.AddToRoleAsync(user, "Medical Officer");

            if (result.Succeeded)
            {
                var medical = new MedicalOfficer()
                {
                    UserName   = model.UserName,
                    Firstname  = model.Firstname,
                    Lastname   = model.Lastname,
                    FacilityId = model.FacilityId,
                    Department = model.Department,
                    ContactNo  = model.ContactNo,
                    CreatedBy  = model.CreatedBy,
                    Created    = DateTime.Now
                };

                _db.Officers.Add(medical);
                if (await _db.SaveChangesAsync() > 0)
                {
                    //  SendSms(model.UserName, password, "Donor Trace", model.ContactNo);
                    return(Ok());
                }
            }


            return(BadRequest("Could not save officer"));
        }
Esempio n. 2
0
        public void SendSms(OfficerDto officer)
        {
            string clientId     = _config.GetValue <string>("Sms:ClientId");
            string clientSecret = _config.GetValue <string>("Sms:ClientSecret");

            StringBuilder builder = new StringBuilder();

            builder.Append("You have been registered on the Donor Trace Mobile App");
            builder.AppendLine();
            builder.Append("Username: "******" " + officer.UserName);
            builder.AppendLine();
            builder.Append("Password: "******" " + officer.Password);

            var             host       = new ApiHost(new BasicAuth(clientId, clientSecret));
            var             messageApi = new MessagingApi(host);
            MessageResponse msg        = messageApi.SendQuickMessage("Donor Trace", officer.ContactNo, builder.ToString(), true);
        }
Esempio n. 3
0
        private static List <OfficerPrisoner> GetOfficersPrisoners(SoftJailDbContext context, Officer officer, OfficerDto officerDto)
        {
            var officerPrisoners = new List <OfficerPrisoner>();

            foreach (var prisonerDto in officerDto.Prisoners)
            {
                var prisoner = context.Prisoners.SingleOrDefault(p => p.Id == prisonerDto.Id);

                var officerPrisoner = new OfficerPrisoner
                {
                    Officer  = officer,
                    Prisoner = prisoner,
                };

                officerPrisoners.Add(officerPrisoner);
            }

            return(officerPrisoners);
        }