public IActionResult GenerateOtp(long id) { var appointment = context.Appointment.FirstOrDefault(x => x.Id == id); var otp = new Random().Next(1000, 9999); appointment.Otp = otp; appointment.OtpExpiry = DateTime.Now.AddMinutes(3); context.SaveChanges(); return(Ok(otp.ToString())); }
public IActionResult RegisterMother(MotherRegistration model) { try { var userExist = context.User.Where(x => x.Username == model.Username).FirstOrDefault(); if (userExist == null) { var user = new User { Username = model.Username, Password = model.Password, Aadhar = model.Aadhar, Mobile = model.Mobile, Email = model.Email, UserType = (short)UserType.Mother, CreatedBy = long.Parse(GetClaimByName("userId")), CreatedDate = DateTime.Now }; context.SaveChanges(); context.User.Add(user); context.SaveChanges(); var mother = new Mother { Name = model.MotherName, HusbandName = model.HusbandName, FertilityDate = model.FertilityDate, ExpectedDeliveryDate = model.ExpectedDeliveryDate, IsHivInfected = model.IsHivInfected, OtherComplications = model.OtherComplications, NumberOfBabies = model.NumberOfBabies, NumberOfPregnency = model.NumberOfPregnency, Anganwadi = model.AnganwadiId, Address = model.Address, Zip = model.Zip, CreatedBy = long.Parse(GetClaimByName("userId")), CreatedDate = DateTime.Now, UserId = user.Id }; context.Mother.Add(mother); context.SaveChanges(); var sampleAppointments = context.SampleAppointmentData.OrderBy(x => x.Id).ToList(); var dateOfAnganwadi = DateTime.Now.Date; foreach (var item in sampleAppointments.Where(x => x.Type == (short)UserType.Anganwadi)) { var appointment = new Appointment { Name = item.Name, Details = item.Details, Type = item.Type, MotherId = mother.Id, ApproverId = model.AnganwadiId, Date = dateOfAnganwadi, CreatedBy = long.Parse(GetClaimByName("userId")), CreatedDate = DateTime.Now }; context.Appointment.Add(appointment); dateOfAnganwadi = dateOfAnganwadi.AddDays(7); } var dateOfDoctor = DateTime.Now.Date; foreach (var item in sampleAppointments.Where(x => x.Type == (short)UserType.Doctor)) { var appointment = new Appointment { Name = item.Name, Details = item.Details, Type = item.Type, MotherId = mother.Id, ApproverId = long.Parse(GetClaimByName("userId")), Date = dateOfDoctor, CreatedBy = long.Parse(GetClaimByName("userId")), CreatedDate = DateTime.Now }; context.Appointment.Add(appointment); dateOfDoctor = dateOfDoctor.AddMonths(1); } context.SaveChanges(); return(Ok()); } return(BadRequest()); } catch (System.Exception) { throw; } }