Exemplo n.º 1
0
        public Local_Municipality CreateMunicipality(Local_Municipality NewEntry)
        {
            var MunicipalityObj = (from p in dbContext.Local_Municipalities
                                   where p.Description.Contains(NewEntry.Description)
                                   select p).FirstOrDefault();

            if (MunicipalityObj == null)
            {
                //var newMunicipality = new Local_Municipalities();
                //newMunicipality.Description = NewEntry.Description;
                //newMunicipality.Area_Id = (from a in dbContext.Areas
                //                          where a.District_Id== NewEntry.Area.District.District_Id
                //                          select a.Area_Id).FirstOrDefault();
                //dbContext.Local_Municipalities.Add(newMunicipality);
                //dbContext.SaveChanges();
                int MunicipalityId = (from s in dbContext.Local_Municipalities
                                      where s.Description == NewEntry.Description
                                      select s.Local_Municipality_Id).FirstOrDefault();
                var NewLocalMunicipality = new Local_Municipality();

                NewLocalMunicipality.Description           = NewEntry.Description;
                NewLocalMunicipality.Local_Municipality_Id = MunicipalityId;
                dbContext.Local_Municipalities.Add(NewLocalMunicipality);
                dbContext.SaveChanges();
                return(NewLocalMunicipality);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public Local_Municipality EditMunicipality(Local_Municipality UpdatedObj)
        {
            var MunicipalityObj = (from p in dbContext.Local_Municipalities
                                   where p.Local_Municipality_Id == UpdatedObj.Local_Municipality_Id
                                   select p).FirstOrDefault();

            MunicipalityObj.Description = UpdatedObj.Description;
            //MunicipalityObj.Area_Id = UpdatedObj.Area_Id;
            dbContext.SaveChanges();
            var MunicipalityObj2 = (from p in dbContext.Local_Municipalities
                                    where p.Local_Municipality_Id == UpdatedObj.Local_Municipality_Id
                                    select p).FirstOrDefault();

            MunicipalityObj2.Description = UpdatedObj.Description;
            dbContext.SaveChanges();
            return(MunicipalityObj);
        }