Esempio n. 1
0
        public virtual ActionResult Create(LendItemViewModel lendItemVM, HttpPostedFileBase uploadfile)
        {
            if (ModelState.IsValid)
            {
                //get currently logged in user
                var dbUser = General.GetCurrentUser(_userRepository);

                lendItemVM.CreatedAt = DateTime.Now;

                var lenditemmodel = _mapper.Map <LendItemViewModel, LendItem>(lendItemVM);
                lenditemmodel.UserId    = dbUser.Id;
                lenditemmodel.User      = lendItemVM.CreatedBy;
                lenditemmodel.Avialable = lenditemmodel.Quantity;
                lenditemmodel.FileId    = null;

                //process Attached Images
                if (uploadfile != null)
                {
                    lendItemVM.ItemImageViewModels = ImageInsert.InsertImages(uploadfile).AsEnumerable();

                    //update lenditem - file ID (only for one image)
                    var firstOrDefault = lendItemVM.ItemImageViewModels.FirstOrDefault();
                    if (firstOrDefault != null)
                    {
                        lenditemmodel.FileId = firstOrDefault.Id;
                    }
                }

                _lendItemRepository.InsertLendItem(lenditemmodel);

                return(RedirectToAction("Index"));
            }

            return(View(lendItemVM));
        }
Esempio n. 2
0
        // GET: LendItems/Details/5
        public virtual ActionResult Details(int Id)
        {
            var model = _lendItemRepository.GetLendItemByID(Id);

            if (model == null)
            {
                return(RedirectToAction(Actions.Index()));
            }

            LendItemViewModel vm = _mapper.Map <LendItem, LendItemViewModel>(model);

            vm.CreatedBy   = model.User;
            vm.Description = model.Description;

            //get images
            if (vm.FileId != null)
            {
                var lenditemImages = _fileRepository.GetFileById(vm.FileId.Value);
                List <FileViewModel> listimages = new List <FileViewModel>();
                FileViewModel        itemFileVM = _mapper.Map <File, FileViewModel>(lenditemImages);
                listimages.Add(itemFileVM);

                //add images to Item VM
                vm.ItemImageViewModels = listimages.AsEnumerable();
            }

            return(View(vm));
        }
Esempio n. 3
0
        // GET: Lends/Details/5
        public virtual ActionResult Details(int Id)
        {
            var model = _lendRepository.GetLendByID(Id);

            if (model == null)
            {
                return(RedirectToAction(Actions.Index()));
            }

            LendViewModel       vm     = _mapper.Map <Lend, LendViewModel>(model);
            LendItemViewModel   ItemVM = _mapper.Map <LendItem, LendItemViewModel>(model.LendItem);
            LendReturnViewModel lrVM   = new LendReturnViewModel();

            //get images of LendReturn
            if (model.LendReturn != null)
            {
                lrVM = _mapper.Map <LendReturn, LendReturnViewModel>(model.LendReturn);

                if (lrVM.FileId != null)
                {
                    File lendreturnImages             = _fileRepository.GetFileById(lrVM.FileId.Value);
                    List <FileViewModel> lrimageslist = new List <FileViewModel>();

                    FileViewModel lrFileVM = _mapper.Map <File, FileViewModel>(lendreturnImages);
                    lrimageslist.Add(lrFileVM);

                    //add values to Return VM
                    lrVM.ReturnImageViewModels = lrimageslist.AsEnumerable();
                }
                lrVM.CreatedBy = model.LendReturn.User;
            }

            //get images of LendItem
            if (ItemVM.FileId != null)
            {
                File lenditemImages             = _fileRepository.GetFileById(ItemVM.FileId.Value);
                List <FileViewModel> listimages = new List <FileViewModel>();
                FileViewModel        itemFileVM = _mapper.Map <File, FileViewModel>(lenditemImages);
                listimages.Add(itemFileVM);

                //add values to ItemVM
                ItemVM.ItemImageViewModels = listimages.AsEnumerable();
            }
            ItemVM.CreatedBy = model.LendItem.User;

            //stick all to LendVM
            vm.CreatedBy        = model.User;
            vm.SelectedLendUser = model.LendUser;
            vm.SelectedLendItem = ItemVM;
            if (lrVM.Id != 0)
            {
                vm.LendReturn = lrVM;
            }

            return(View(vm));
        }
Esempio n. 4
0
        // GET: LendItems/Create
        public virtual ActionResult Create()
        {
            ApplicationUser Auser  = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
            var             dbUser = _userRepository.GetUserByEmail(Auser.Email);

            var viewmodel = new LendItemViewModel();

            viewmodel.CurrentUserwithID = dbUser.UserName + " (" + dbUser.Id + ")";

            return(View(viewmodel));
        }
Esempio n. 5
0
        // GET: LendItems/Edit/5
        public virtual ActionResult Edit(int Id)
        {
            var model = _lendItemRepository.GetLendItemByID(Id);

            if (model == null)
            {
                return(RedirectToAction(Actions.Index()));
            }

            LendItemViewModel vm = _mapper.Map <LendItem, LendItemViewModel>(model);

            return(View(vm));
        }
Esempio n. 6
0
        public virtual ActionResult Edit(LendItemViewModel lendItemVM, HttpPostedFileBase uploadfile)
        {
            if (ModelState.IsValid)
            {
                //get data from DB
                var model = _lendItemRepository.GetLendItemByID(lendItemVM.Id);

                //convert vm into Model for comparing / updating values
                var updatedlineitemmodel = _mapper.Map <LendItemViewModel, LendItem>(lendItemVM);

                model.Id          = updatedlineitemmodel.Id;
                model.Name        = updatedlineitemmodel.Name;
                model.Description = updatedlineitemmodel.Description;
                model.CustomerId  = updatedlineitemmodel.CustomerId;
                model.Condition   = updatedlineitemmodel.Condition;

                if (updatedlineitemmodel.Quantity < model.Quantity && (model.Quantity - model.Avialable) > updatedlineitemmodel.Quantity)
                {
                    ModelState.AddModelError("availability", "es sind bereits Ausleihungen getätigt worden für diesen Gegenstand");
                    return(View(lendItemVM));
                }
                else
                {
                    model.Quantity = updatedlineitemmodel.Quantity;
                }

                //process Attached Images
                if (uploadfile != null)
                {
                    lendItemVM.ItemImageViewModels = ImageInsert.InsertImages(uploadfile).AsEnumerable();

                    //update lenditem - file ID (only for one image)
                    var firstOrDefault = lendItemVM.ItemImageViewModels.FirstOrDefault();
                    if (firstOrDefault != null)
                    {
                        lendItemVM.FileId = firstOrDefault.Id;
                    }

                    model.FileId = lendItemVM.FileId;
                }

                _lendItemRepository.UpdateLendItem(model);

                return(RedirectToAction("Index"));
            }

            return(View(lendItemVM));
        }