public void UpdateUploadPhoto(UploadPhoto_Infra inst) { var tempInst = context.UploadPhotos.FirstOrDefault(_ => _.Id == inst.Id); tempInst.Id = inst.Id; tempInst.Repareobject_InfraId = inst.Repareobject_InfraId; tempInst.File = inst.File; tempInst.FileName = inst.FileName; tempInst.FileType = inst.FileType; context.SaveChanges(); }
//Метод возвращает Id вновь созданного Файла public int?CreateUploadPhoto(UploadPhoto_Infra inst) { UploadPhoto_Infra temp = inst as UploadPhoto_Infra; temp.File = inst.File; temp.FileName = inst.FileName; temp.FileType = inst.FileType; temp.Id = null; temp.Repareobject_InfraId = inst.Repareobject_InfraId; context.UploadPhotos.Add(temp); context.SaveChanges(); UploadPhoto_Infra tempId = context.UploadPhotos .Last(_ => _.Repareobject_InfraId == temp.Repareobject_InfraId) ; return(tempId.Id); }
public static UploadPhoto_Domain UploadPhotoFromInfraToDomain(this UploadPhoto_Infra @this) { if (@this != null) { return(new UploadPhoto_Domain() { Id = @this.Id, File = @this.File, FileName = @this.FileName, FileType = @this.FileType, Repareobject_DomainId = @this.Repareobject_InfraId }); } else { return(null); } }
//Вспомогательный метод - получение коллекции всех фото по id обьекта ремонта (Repareobject) public IEnumerable <UploadPhoto_Infra> AllUploadPhotosByIdOfObject(int?id) { List <UploadPhoto_Infra> upload = context.UploadPhotos .Where(_ => _.Repareobject_InfraId == id) .ToList() ; if (upload != null) { return(upload); } else { List <UploadPhoto_Infra> templist = new List <UploadPhoto_Infra>(); UploadPhoto_Infra temp = new UploadPhoto_Infra { }; templist.Add(temp); return(templist); } }