public static BuildingPrimitive GetPrimitive(this Building entity) { BuildingPrimitive primitive = new BuildingPrimitive(); primitive.Id = entity.Id; primitive.InternalName = entity.InternalName; primitive.ZIPCode = entity.ZIPCode; primitive.City = entity.City; primitive.Street = entity.Street; primitive.Phone = entity.Phone; primitive.ContactPerson = entity.ContactPerson; primitive.ContactPersonPhone = entity.ContactPersonPhone; primitive.HouseNo = entity.HouseNo; primitive.Deleted = entity.Deleted; primitive.Deactivated = entity.Deactivated; primitive.Name = entity.Name; return primitive; }
public void CreateOrUpdateBuilding(BuildingPrimitive buildingPrimitive) { try { using (SmartWorkingEntities context = new SmartWorkingEntities()) { Building building = buildingPrimitive.GetEntity(); Building existingObject = context.Buildings.Where(x => x.Id == building.Id).FirstOrDefault(); //no record of this item in the DB, item being passed in has a PK if (existingObject == null && building.Id > 0) { throw new FaultException<ExceptionDetail>(new ExceptionDetail(new Exception("Błąd zapisu do bazy")), "Obiekt nie istniał w bazie, a jego Id jest większe od 0."); } //Item has no PK value, must be new else if (building.Id <= 0) { context.Buildings.AddObject(building); } //Item was retrieved, and the item passed has a valid ID, do an update else { context.Buildings.ApplyCurrentValues(building); } context.SaveChanges(); } } catch (Exception e) { throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message); } }
public static BuildingPrimitive GetPrimitiveCopy(this BuildingPrimitive primitiveToCopy) { if (primitiveToCopy == null) return null; BuildingPrimitive primitive = new BuildingPrimitive(); primitive.Id = primitiveToCopy.Id; primitive.InternalName = primitiveToCopy.InternalName; primitive.ZIPCode = primitiveToCopy.ZIPCode; primitive.City = primitiveToCopy.City; primitive.Street = primitiveToCopy.Street; primitive.Phone = primitiveToCopy.Phone; primitive.ContactPerson = primitiveToCopy.ContactPerson; primitive.ContactPersonPhone = primitiveToCopy.ContactPersonPhone; primitive.HouseNo = primitiveToCopy.HouseNo; primitive.Deleted = primitiveToCopy.Deleted; primitive.Deactivated = primitiveToCopy.Deactivated; primitive.Name = primitiveToCopy.Name; return primitive; }
public void DeleteBuilding(BuildingPrimitive buildingPrimitive) { try { using (SmartWorkingEntities context = new SmartWorkingEntities()) { Building building = context.Buildings.Where(x => x.Id == buildingPrimitive.Id).FirstOrDefault(); if (building != null) { building.Deleted = DateTime.Now; context.SaveChanges(); } else { throw new Exception("This car does not exist in db."); } } } catch (Exception e) { throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message); } }