// GET: InventoryTransfers/Edit/5
        public ActionResult Edit(int?id)
        {
            //ViewBag.ReturnUrl = Request.UrlReferrer;
            var invtransfer = db.InventoryTransfers.SingleOrDefault(c => c.InventoryTransferId == id);

            var invLocation       = db.InvLocation.ToList();
            var finishInvLocation = db.FinishInvLocation.ToList();

            var viewModel = new InventoryTransferViewModel()
            {
                InventoryTransfer  = invtransfer,
                InvLocations       = invLocation,
                FinishInvLocations = finishInvLocation
            };

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //InventoryTransfer inventoryTransfer = db.InventoryTransfers.Find(id);
            InventoryTransfer inventoryTransfer = db.InventoryTransfers.Include(s => s.FileInvDetails).SingleOrDefault(x => x.InventoryTransferId == id);

            if (inventoryTransfer == null)
            {
                return(HttpNotFound());
            }
            return(View("Edit", viewModel));
            //return View(inventoryTransfer);
        }
        /// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(InventoryTransferViewModel model)
        {
            var entity = model.ToEntity();

            this._InventoryTransfersRepository.Delete(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion
        }
        /// <summary>
        /// Throw an exception if name is exist.
        /// </summary>
        /// <param name="model">InventoryTransfer view model</param>
        public void ThrowExceptionIfExist(InventoryTransferViewModel model)
        {
            ConditionFilter <InventoryTransfer, long> condition = new ConditionFilter <InventoryTransfer, long>
            {
                Query = (entity =>
                         entity.Code == model.Code &&
                         entity.Id != model.Id)
            };
            var existEntity = this._InventoryTransfersRepository.Get(condition).FirstOrDefault();

            if (existEntity != null)
            {
                throw new ItemAlreadyExistException();
            }
        }
        // GET: InventoryTransfers/Create
        public ActionResult Create()
        {
            ViewBag.ReturnUrl = Request.UrlReferrer;
            var invLocation       = db.InvLocation.ToList();
            var finishInvLocation = db.FinishInvLocation.ToList();

            var viewModel = new InventoryTransferViewModel()
            {
                InvLocations       = invLocation,
                FinishInvLocations = finishInvLocation
            };

            //return View();

            return(View("Create", viewModel));
        }
        /// <summary>
        /// Update an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public InventoryTransferViewModel Update(InventoryTransferViewModel model)
        {
            this.ThrowExceptionIfExist(model);
            //this._closedMonthsService.ValidateIfMonthIsClosed(model.Date);

            var entity = model.ToEntity();

            entity = this._InventoryTransfersRepository.Update(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion

            model = entity.ToModel();
            return(model);
        }