public ApiResponse AddUpdateInformation(Information information) { try { var _information = _context.Information.FirstOrDefault(); if (_information != null) { _information.Vaccination = information.Vaccination; _information.FertilityManagement = information.FertilityManagement; _information.HygenicMilk = information.HygenicMilk; _context.SaveChanges(); return(new ApiResponse { Added = true, Message = "Saved successfully." }); } _context.Information.Add(information); _context.SaveChanges(); return(new ApiResponse { Added = true, Message = "Saved successfully." }); } catch (Exception) { return(new ApiResponse { Added = false, Message = "Error occured. Please try again..." }); } }
public ApiResponse AddBookingSlot(BookingSlot bookingSlot) { try { var _bookingSlot = _context.BookingSlots.FirstOrDefault(b => b.Day == bookingSlot.Day && b.FromTo == bookingSlot.FromTo); if (_bookingSlot != null) { return(new ApiResponse { Added = false, Message = "Booking Slot already added for " + bookingSlot.Day }); } _context.BookingSlots.Add(bookingSlot); _context.SaveChanges(); return(new ApiResponse { Added = true, Message = "Booking Slot added successfully." }); } catch (Exception) { return(new ApiResponse { Added = false, Message = "Error occured. Please try again..." }); } }
public ApiResponse AddMessage(Conversation conversation) { try { ConversationHistoryDAL _dal = new ConversationHistoryDAL(); conversation.AddedOn = DateTime.Now; _context.Conversations.Add(conversation); _context.SaveChanges(); _dal.AddConversationHistory(conversation.Sender, conversation.Receiver, conversation.Message); return(new ApiResponse { Added = true, Message = "Conversation added successfully." }); } catch (Exception) { return(new ApiResponse { Added = false, Message = "Error occured. Please try again..." }); } }
public ApiResponse AddConversationHistory(string sender, string receiver, string message) { using (var transaction = _context.Database.BeginTransaction()) { try { var conversationHistory = _context.ConversationHistories.Where(c => (c.Sender == sender && c.Receiver == receiver) || (c.Sender == receiver && c.Receiver == sender)) .FirstOrDefault(); if (conversationHistory != null) { _context.ConversationHistories.Remove(conversationHistory); _context.SaveChanges(); } _context.ConversationHistories.Add(new ConversationHistory { Sender = sender, Receiver = receiver, Message = message, AddedOn = DateTime.Now }); _context.SaveChanges(); transaction.Commit(); return(new ApiResponse { Added = true, Message = "Conversation History saved successfully." }); } catch (Exception) { transaction.Rollback(); return(new ApiResponse { Added = false, Message = "Error occured. Please try again..." }); } } }
public ApiResponse GenerateAdmin(string password) { try { User adminUser = _context.Users.Where(u => u.Mobile == "8715995492").FirstOrDefault(); if (adminUser != null) { _context.Users.Remove(adminUser); _context.SaveChanges(); } User admin = new User { ID = Guid.NewGuid(), Name = "Admin", Password = password, Email = "*****@*****.**", Role = "Admin", Mobile = "8715995492", IsActive = true }; _context.Users.Add(admin); _context.SaveChanges(); return(new ApiResponse { Added = true, Message = "Admin generated successfully" }); } catch (Exception ex) { return(new ApiResponse { Added = false, Message = "Error occured. Please try again..." }); } }
public ApiResponse BookAppointment(long bookingSlotId, DateTime bookingDate, string mobile, string name, string address, string contactNo, string petName) { try { var bookingSlot = _context.BookingSlots.FirstOrDefault(b => b.ID == bookingSlotId); if (bookingSlot == null) { return(new ApiResponse { Added = false, Message = "Booking Slot not found." }); } var numPatients = bookingSlot.NumPatients; var numAppointmentsBooked = _context.Appointments.Where(a => a.AppointmentDate == bookingDate && a.BookingSlotID == bookingSlotId).Count(); if (numAppointmentsBooked >= numPatients) { return(new ApiResponse { Added = false, Message = "Appointment not available. Please try another booking slot." }); } var appointmentInDb = _context.Appointments.FirstOrDefault(a => a.Mobile == mobile && a.AppointmentDate == bookingDate && a.BookingSlotID == bookingSlotId); if (appointmentInDb != null) { return(new ApiResponse { Added = false, Message = "Appointment for the selected Date and Booking Slot already booked. Please select another Appointment Date/Booking Slot/Doctor" }); } var appointment = new Appointment { Mobile = mobile, Name = name, Address = address, ContactNo = contactNo, PetName = petName, AppointmentDate = bookingDate, BookingSlotID = bookingSlotId, TokenNo = numAppointmentsBooked + 1 }; _context.Appointments.Add(appointment); _context.SaveChanges(); return(new ApiResponse { Added = true, Message = "Appointment fixed successfully. Your Token No is " + (numAppointmentsBooked + 1) }); } catch (Exception) { return(new ApiResponse { Added = false, Message = "Error occured. Please try again..." }); } }