public async Task <IActionResult> CompleteRegister([FromBody] CompleteRegisterDAO complete) { var response = await _registerRepository.CompleteRegister(complete); if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(Ok(new Response { Status = response.StatusCode.ToString(), Message = response.Message })); } else { return(StatusCode((int)response.StatusCode, new Response { Status = "Error", Message = response.Message })); } }
public async Task <StatusResponse <bool> > CompleteRegister(CompleteRegisterDAO completeRegisterDAO) { var response = new StatusResponse <bool>(); try { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var address = _mapper.Map <Address>(completeRegisterDAO.AddressInfo); var medical = _mapper.Map <MedicalRecord>(completeRegisterDAO.MedicalInfo); var contacts = _mapper.Map <List <EmergencyContact> >(completeRegisterDAO.ContactInfos); var validDevice = await _context.MobileDeviceRegistrationTemps .Where(x => x.DeviceId == completeRegisterDAO.DeviceId && x.IsCompleteRegister == false) .FirstOrDefaultAsync(); if (validDevice != null) { var user = await _context.appUsers.FindAsync(validDevice.AppUserId); user.Name = completeRegisterDAO.PersonalInfo.Name; user.MiddleName = completeRegisterDAO.PersonalInfo.MiddleName; user.LastName = completeRegisterDAO.PersonalInfo.LastName; //TODO: completar con datos de la tabla [AspNetUsers] de los campos de firebase para poder enviar y recibir notificaciones Citizen citizen = new Citizen { AspNetUserId = user.Id, appUser = user, CURP = completeRegisterDAO.PersonalInfo.Curp, DateOfBirth = completeRegisterDAO.PersonalInfo.DateOfBirth, Sex = completeRegisterDAO.PersonalInfo.Sex }; _context.Entry(user).State = EntityState.Modified; _context.citizens.Add(citizen); await _context.SaveChangesAsync(); var suburb = await _context.suburbs.FindAsync(address.SuburbId); if (suburb == null) { response.StatusCode = HttpStatusCode.NotFound; response.Message = "Validar envio de colonia para poder completar su registro"; response.Value = false; return(response); } address.CitizenId = citizen.CitizenId; address.citizen = citizen; medical.CitizenId = citizen.CitizenId; medical.citizen = citizen; contacts.ForEach(x => { x.CitizenId = citizen.CitizenId; x.citizen = citizen; }); await _context.addresses.AddAsync(address); await _context.medicalRecords.AddAsync(medical); await _context.emergencyContacts.AddRangeAsync(contacts); await _context.SaveChangesAsync(); } else { response.StatusCode = HttpStatusCode.NotFound; response.Message = "El dispositico donde incio el registro no es mismo, favor de verificar para continuar con el registro"; response.Value = false; return(response); } validDevice.IsCompleteRegister = true; _context.Entry(validDevice).State = EntityState.Modified; await _context.SaveChangesAsync(); scope.Complete(); response.StatusCode = HttpStatusCode.OK; response.Message = "Registro completado correctamente su cuenta sera validada en breve, agradecemos su comprensión"; response.Value = true; return(response); } } catch (Exception e) { SystemLog systemLog = new SystemLog(); systemLog.Description = e.ToMessageAndCompleteStacktrace(); systemLog.DateLog = DateTime.UtcNow.ToLocalTime(); systemLog.Controller = GetType().Name; systemLog.Action = UtilitiesAIO.GetCallerMemberName(); systemLog.Parameter = JsonConvert.SerializeObject(completeRegisterDAO); _customSystemLog.AddLog(systemLog); } return(null); }