public static List <LibraryItemVM> MappLibraryItemToVM(List <DataLibrary.Models.LibraryItemModel> input) { var output = new List <LibraryItemVM>(); foreach (var item in input) { var model = new LibraryItemVM(); var category = new Category(); if (item.CategoryId > 0) { category = new Category() { Id = CategoryProcessor.EditCategory(item.CategoryId).Id, CategoryName = CategoryProcessor.EditCategory(item.CategoryId).CategoryName }; } model.Author = item.Author; model.BorrowDate = item.BorrowDate; model.Borrower = item.Borrower; model.Category = category; model.Id = item.Id; model.IsBorrowable = item.IsBorrowable; model.Pages = item.Pages; model.RunTimeMinutes = item.RunTimeMinutes; model.Title = item.Title; model.Type = item.Type; output.Add(model); } return(output); }
public static LibraryItemVM MappForEditToVM(DataLibrary.Models.LibraryItemModel item) { var model = new LibraryItemVM(); var category = new Category(); if (item.CategoryId > 0) { category = new Category() { Id = CategoryProcessor.EditCategory(item.CategoryId).Id, CategoryName = CategoryProcessor.EditCategory(item.CategoryId).CategoryName }; } model.Author = item.Author; model.BorrowDate = item.BorrowDate; model.Borrower = item.Borrower; model.Category = category; model.Id = item.Id; model.IsBorrowable = item.IsBorrowable; model.Pages = item.Pages; model.RunTimeMinutes = item.RunTimeMinutes; model.Title = item.Title; model.Type = item.Type; return(model); }
// Library item logic public static LibraryItemVM SetIsBorrowable(LibraryItemVM model) { if (model.Type == "Reference book") { model.IsBorrowable = false; } return(model); }
//Category logic public static LibraryItemVM CleanCategory(LibraryItemVM model) { var category = new Category(); var tempCategory = CategoryProcessor.GetCategoryByName(model.CategoryName); category.CategoryName = tempCategory.CategoryName; category.Id = tempCategory.Id; model.Category = category; return(model); }
public static LibraryItemVM SetBorrowDate(LibraryItemVM model) { if (model.Borrower != null) { model.BorrowDate = DateTime.Now; } else { model.BorrowDate = null; } return(model); }
public ActionResult Edit(LibraryItemVM model) { if (ModelState.IsValid) { model = LogicClass.SerCategoryFromVM(model); model = LogicClass.SetBorrowDate(model); var outModel = mapping.MappToLibraryItemModelFromVM(model); LibraryItemProcessor.SaveLibraryItem(outModel); } return(RedirectToAction("Index")); }
public ActionResult Create(LibraryItemVM model) { if (model.CategoryName != "" || model.CategoryName != null) { model = LogicClass.CleanCategory(model); } if (ModelState.IsValid) { model = LogicClass.SetIsBorrowable(model); LibraryItemProcessor.CreateLibraryItem(mapping.MappToLibraryItemModelFromVM(model)); return(RedirectToAction("Index")); } return(RedirectToAction("Create")); }
public static LibraryItemVM SerCategoryFromVM(LibraryItemVM model) { var category = model.CategoryName; if (model.Category.CategoryName != category) { foreach (var item in model.CategoryList) { if (item.CategoryName == category) { model.Category = item; } } } return(model); }
public static LibraryItemModel MappToLibraryItemModelFromVM(LibraryItemVM item) { var model = new LibraryItemModel(); var category = CategoryProcessor.GetCategoryByName(item.Category.CategoryName); model.Author = item.Author; model.BorrowDate = item.BorrowDate; model.Borrower = item.Borrower; model.CategoryId = category.Id; model.Id = item.Id; model.IsBorrowable = item.IsBorrowable; model.Pages = item.Pages; model.RunTimeMinutes = item.RunTimeMinutes; model.Title = item.Title; model.Type = item.Type; return(model); }