public PetModel AddOrEditPet(PetModel model, OwnerModel ownerModel) { OwnerService ownerLogic = new OwnerService(); var owner = ownerLogic.AddOrEditOwner(ownerModel); Pet pet = new Pet(); using (var db = new PawsAndClawsEntities()) { pet = db.Pets.Where(i => i.PetId == model.PetId).FirstOrDefault(); if (pet != null) { pet.PetName = model.PetName; pet.Type = model.Type; pet.OwnerId = model.OwnerId; } else { model.OwnerId = owner.OwnerId; pet = db.Pets.Add(model.ToDTO()); } db.SaveChanges(); } return(new PetModel(pet)); }
public OwnerModel AddOrEditOwner(OwnerModel model) { Owner owner = new Owner(); using (var db = new PawsAndClawsEntities()) { owner = db.Owners.Where(i => i.OwnerId == model.OwnerId).FirstOrDefault(); if (owner != null) { owner.First = model.First; owner.Last = model.Last; owner.Phone = model.Phone; owner.Address = model.Address; } else { owner = db.Owners.Add(model.ToDTO()); } db.SaveChanges(); } return(new OwnerModel(owner)); }
public AppointmentModel AddOrEditAppointment(AppointmentViewModel model) { PetModel petModel = new PetModel() { PetId = model.PetId, PetName = model.PetName, Type = model.Type, OwnerId = model.OwnerId }; OwnerModel ownerModel = new OwnerModel() { OwnerId = model.OwnerId, First = model.First, Last = model.Last, Phone = model.Phone, Address = model.Address }; AppointmentModel appointmentModel = new AppointmentModel() { AppointmentId = model.AppointmentId, PetId = model.PetId, AppointmentDate = model.AppointmentDate, AppointmentReason = model.AppointmentReason }; PetService petLogic = new PetService(); var pet = petLogic.AddOrEditPet(petModel, ownerModel); Appointment appointment = new Appointment(); using (var db = new PawsAndClawsEntities()) { appointment = db.Appointments.Where(i => i.AppointmentId == model.AppointmentId).FirstOrDefault(); if (appointment != null) { appointment.AppointmentDate = model.AppointmentDate; appointment.AppointmentReason = model.AppointmentReason; appointment.PetId = model.PetId; } else { appointmentModel.PetId = pet.PetId; appointment = db.Appointments.Add(appointmentModel.ToDTO()); } db.SaveChanges(); } return(appointmentModel); }
public AppointmentModel DeleteAppointmentById(int appointmentId) { Appointment appointment = new Appointment(); using (var db = new PawsAndClawsEntities()) { appointment = db.Appointments.Where(i => i.AppointmentId == appointmentId).FirstOrDefault(); db.Appointments.Remove(appointment); db.SaveChanges(); } return(new AppointmentModel(appointment));; }