Пример #1
0
 public static ShelterDTO UpdateShelter(ShelterDTO updatedShelter, ref string message)
 {
     DAL.Shelter shelterToUpdate = db.Shelters.FirstOrDefault(s => s.ShelterKey == updatedShelter.ShelterKey);
     if (shelterToUpdate == null)
     {
         message = "לא נמצא מקלט מבוקש";
         return(null);
     }
     else
     {
         shelterToUpdate.City               = updatedShelter.City;
         shelterToUpdate.ShelterStreet      = updatedShelter.ShelterStreet;
         shelterToUpdate.StreetNumber       = updatedShelter.StreetNumber;
         shelterToUpdate.MaxPeople          = updatedShelter.MaxPeople;
         shelterToUpdate.ShelterDescription = updatedShelter.ShelterDescription;
         db.SaveChanges();
     }
     return(updatedShelter);
 }
Пример #2
0
        public static ShelterDTO AddNewShelter(ShelterDTO newShelter, ref string message)
        {
            //DAL.Shelter ifCityExists = db.Shelters.FirstOrDefault(s => s.City == newShelter.City);
            //DAL.Shelter ifStreetExists = db.Shelters.FirstOrDefault(s => s.ShelterStreet == newShelter.ShelterStreet);
            //DAL.Shelter ifStreetNumberExists = db.Shelters.FirstOrDefault(s => s.StreetNumber == newShelter.StreetNumber);
            bool ifExists = false;

            foreach (var shelter in db.Shelters)
            {
                if (shelter.City == newShelter.City)
                {
                    if (shelter.ShelterStreet == newShelter.ShelterStreet)
                    {
                        if (shelter.StreetNumber == newShelter.StreetNumber)
                        {
                            ifExists = true;
                            break;
                        }
                    }
                }
            }
            if (ifExists)
            {
                message = "מקלט זה קיים במערכת";
                return(null);
            }
            DAL.Shelter shelterDAL = ShelterDTO.DtoToDAL(newShelter);
            db.Shelters.Add(shelterDAL);
            try
            {
                db.SaveChanges();
                return(newShelter);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }