public PhotoVm GetPhotoById(int photoId) { using (var model = new PhotoBEntities()) { var photo = model.Photos.FirstOrDefault(x => x.Id == photoId); if (photo != null) { return(new PhotoVm { Id = photo.Id, Number = photo.Number, Name = photo.Name, CategoryId = photo.CategoryId, CategoryName = photo.Category.Name, ImagePath = photo.ImagePath, Price = photo.Price, Author = photo.Author, DateListed = photo.DateListed, LastChanged = photo.LastChanged, LastChangedBy = photo.LastChangedBy }); } else { return(null); } } }
public bool CheckCategoryInUse(int categoryId) { using (var model = new PhotoBEntities()) { return(model.Photos.Any(x => x.CategoryId == categoryId)); } }
public void DeleteCategory(int photoId) { using (var model = new PhotoBEntities()) { var photo = model.Photos.FirstOrDefault(x => x.Id == photoId); if (photo != null) { model.Photos.Remove(photo); model.SaveChanges(); } } }
public void DeleteCategory(int categoryId) { using (var model = new PhotoBEntities()) { var category = model.Categories.FirstOrDefault(x => x.Id == categoryId); if (category != null) { model.Categories.Remove(category); } model.SaveChanges(); } }
public CategoryVm[] GetCategoryList() { using (var model = new PhotoBEntities()) { return(model.Categories.Select(x => new CategoryVm { Id = x.Id, Name = x.Name, Description = x.Description, LastChangedBy = x.LastChangedBy, LastChanged = x.LastChanged }).ToArray()); } }
public void UpdateCategory(CategoryVm categoryVm) { using (var model = new PhotoBEntities()) { var category = model.Categories.FirstOrDefault(x => x.Id == categoryVm.Id); if (category != null) { category.Name = categoryVm.Name; category.Description = categoryVm.Description; category.LastChangedBy = "System"; category.LastChanged = DateTime.Now; } model.SaveChanges(); } }
public void EditCategory(CategoryVm categoryVm) { using (var model = new PhotoBEntities()) { var category = new Category { Name = categoryVm.Name, Description = categoryVm.Description, LastChangedBy = "System", LastChanged = DateTime.Now }; model.Categories.Add(category); model.SaveChanges(); } }
public PhotoVm[] GetPhotoList() { using (var model = new PhotoBEntities()) { return(model.Photos.Select(x => new PhotoVm { Id = x.Id, CategoryId = x.CategoryId, CategoryName = x.Category.Name, Name = x.Name, Number = x.Number, ImagePath = x.ImagePath, Price = x.Price, DateListed = x.DateListed, Author = x.Author } ).ToArray()); } }
public void Updatephoto(PhotoVm photoVm) { using (var model = new PhotoBEntities()) { var photo = model.Photos.FirstOrDefault(x => x.Id == photoVm.Id); if (photo != null) { photo.Name = photoVm.Name; photo.Number = photoVm.Number; photo.CategoryId = photoVm.CategoryId.Value; photo.Price = photoVm.Price.Value; photo.ImagePath = photoVm.ImagePath; photo.Author = photoVm.Author; photo.LastChangedBy = "System"; photo.LastChanged = DateTime.Now; } model.SaveChanges(); } }
public void EditPhoto(PhotoVm photoVm) { using (var model = new PhotoBEntities()) { var photo = new Photo { Name = photoVm.Name, Number = photoVm.Number, CategoryId = photoVm.CategoryId.Value, Price = photoVm.Price.Value, ImagePath = photoVm.ImagePath, DateListed = DateTime.Now, Author = photoVm.Author, LastChangedBy = "System", LastChanged = DateTime.Now }; model.Photos.Add(photo); model.SaveChanges(); } }
public CategoryVm GetCategoryById(int categoryId) { using (var model = new PhotoBEntities()) { var category = model.Categories.FirstOrDefault(x => x.Id == categoryId); if (category != null) { return(new CategoryVm { Id = category.Id, Name = category.Name, Description = category.Description, LastChanged = category.LastChanged, LastChangedBy = category.LastChangedBy }); } else { return(null); } } }