Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 // Library item logic
 public static LibraryItemVM SetIsBorrowable(LibraryItemVM model)
 {
     if (model.Type == "Reference book")
     {
         model.IsBorrowable = false;
     }
     return(model);
 }
Beispiel #4
0
        //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);
        }
Beispiel #5
0
        public static LibraryItemVM SetBorrowDate(LibraryItemVM model)
        {
            if (model.Borrower != null)
            {
                model.BorrowDate = DateTime.Now;
            }
            else
            {
                model.BorrowDate = null;
            }


            return(model);
        }
Beispiel #6
0
        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"));
        }
Beispiel #7
0
        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"));
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }