public string SaveUpdateTenanatPet(PetModel model, long UserId) { string msg = ""; ShomaRMEntities db = new ShomaRMEntities(); var applyNow = db.tbl_ApplyNow.Where(co => co.UserId == UserId).FirstOrDefault(); if (applyNow != null) { if (model.PetID == 0) { var savePet = new tbl_TenantPet() { PetID = model.PetID, TenantID = applyNow.ID, PetType = model.PetType, Breed = model.Breed, Weight = model.Weight, Age = model.Age, Photo = model.Photo, PetVaccinationCert = model.PetVaccinationCertificate, OriginalPhoto = model.OriginalPetNameFile, OriginalVaccinationCert = model.OriginalPetVaccinationCertificateFile, PetName = model.PetName, VetsName = model.VetsName }; db.tbl_TenantPet.Add(savePet); db.SaveChanges(); //msg = savePet.TenantID.ToString(); msg += "Pet Saved Successfully"; } else { var getPetdata = db.tbl_TenantPet.Where(p => p.PetID == model.PetID).FirstOrDefault(); if (getPetdata != null) { getPetdata.PetID = model.PetID; getPetdata.TenantID = applyNow.ID; getPetdata.PetType = model.PetType; getPetdata.Breed = model.Breed; getPetdata.Weight = model.Weight; getPetdata.Age = model.Age; getPetdata.Photo = model.Photo; getPetdata.PetVaccinationCert = model.PetVaccinationCertificate; getPetdata.OriginalPhoto = model.OriginalPetNameFile; getPetdata.OriginalVaccinationCert = model.OriginalPetVaccinationCertificateFile; getPetdata.PetName = model.PetName; getPetdata.VetsName = model.VetsName; } db.SaveChanges(); msg = "Pet Updated Successfully"; } } db.Dispose(); return(msg); }
public string SaveUpdatePet(PetModel model) { string msg = ""; ShomaRMEntities db = new ShomaRMEntities(); int userid = ShomaRM.Models.ShomaGroupWebSession.CurrentUser != null ? ShomaRM.Models.ShomaGroupWebSession.CurrentUser.UserID : 0; var availableSpace = db.tbl_TenantPetPlace.Where(p => p.TenantID == model.TenantID).FirstOrDefault(); var availablePetList = db.tbl_TenantPet.Where(p => p.TenantID == model.TenantID).ToList(); if (availableSpace != null && availablePetList != null) { if (availablePetList.Count < availableSpace.PetPlaceID) { if (model.PetID == 0) { var savePet = new tbl_TenantPet() { PetID = model.PetID, TenantID = model.TenantID, PetType = model.PetType, Breed = model.Breed, Weight = model.Weight, Age = model.Age, Photo = model.Photo, PetVaccinationCert = model.PetVaccinationCertificate, OriginalPhoto = model.OriginalPetNameFile, OriginalVaccinationCert = model.OriginalPetVaccinationCertificateFile, PetName = model.PetName, VetsName = model.VetsName, AddedBy = model.CurrentUserId }; db.tbl_TenantPet.Add(savePet); db.SaveChanges(); msg = savePet.TenantID.ToString(); msg += ",Pet Saved Successfully"; } } else { msg = ",You can not add Pet Due to Un-available Pet Space"; } } if (model.PetID != 0) { var getPetdata = db.tbl_TenantPet.Where(p => p.PetID == model.PetID).FirstOrDefault(); if (getPetdata != null) { getPetdata.PetID = model.PetID; getPetdata.TenantID = model.TenantID; getPetdata.PetType = model.PetType; getPetdata.Breed = model.Breed; getPetdata.Weight = model.Weight; getPetdata.Age = model.Age; getPetdata.Photo = model.Photo; getPetdata.PetVaccinationCert = model.PetVaccinationCertificate; getPetdata.OriginalPhoto = model.OriginalPetNameFile; getPetdata.OriginalVaccinationCert = model.OriginalPetVaccinationCertificateFile; getPetdata.PetName = model.PetName; getPetdata.VetsName = model.VetsName; } db.SaveChanges(); msg = ",Pet Updated Successfully"; } db.Dispose(); return(msg); }