public ActionResult ViewShipmentsByProducer(long ProducerID)
        {
            ShipmentVM newVM = new ShipmentVM();

            if (Session["UserName"] != null && (int)Session["UserLevel"] <= 2)
            {
                try
                {
                    //call to db to get ships by loc, then map list data to presentation list obj.
                    List <IShipmentInfoDO> shipmentData = _ShipmentAccess.ViewShipmentsByProducer(ProducerID);
                    newVM.ShipmentList = ShipmentMap.MapDOtoPO(shipmentData);
                }
                catch (Exception)
                {
                    newVM.ErrorMessage = "There was an issue obtaining the list";
                }
                finally
                {
                    ///nothing else needs to happen
                }
            }
            else
            {
                RedirectToAction("Login", "User");
            }
            return(View(newVM));
        }
        public ActionResult ViewShipments()
        {
            ActionResult oResponse = null;
            ShipmentVM   newVM     = new ShipmentVM();

            if (Session["UserName"] != null && ((int)Session["UserLevel"] == 2 || (int)Session["UserLevel"] == 1))
            {
                try
                {
                    //call to db to obtain all shipments, then map list data to presentation list obj.
                    List <IShipmentInfoDO> shipmentData = _ShipmentAccess.ViewAllShipments();
                    newVM.ShipmentList = ShipmentMap.MapDOtoPO(shipmentData);
                }
                catch (Exception)
                {
                    newVM.ErrorMessage = "There was an issue obtaining the list";
                }
                finally
                {
                    oResponse = View(newVM);
                }
            }
            else
            {
                oResponse = RedirectToAction("Login", "User");
            }
            return(oResponse);
        }
        public ActionResult AddShipment(ShipmentVM viewModel)
        {
            ActionResult oResponse = null;

            if (Session["UserName"] != null && (int)Session["UserLevel"] <= 2)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        IShipmentInfoDO shipmentform = ShipmentMap.MapPOtoDO(viewModel.Shipment);
                        //call to method in DAL to view shipment by producerID
                        _ShipmentAccess.InsertShipment(shipmentform);
                    }
                    catch (Exception e)
                    {
                        if (e.Message.Contains("duplicate"))
                        {
                            viewModel.ErrorMessage = String.Format("There is already a {0} in the database.", viewModel.Shipment.ShipmentID);
                        }
                        else
                        {
                            viewModel.ErrorMessage = "We apologize but we were unable to handle your request at this time.";
                        }
                    }
                    finally
                    {
                        //nothing to do here
                    }
                    if (viewModel.ErrorMessage == null)
                    {
                        oResponse = RedirectToAction("ViewShipments", "Shipment");
                    }
                    else
                    {
                        //Data call here to re-get the locations and producers.
                        viewModel.Shipment.ProducerDDL = PopulateProducersDDL();
                        viewModel.Shipment.LocationDDL = PopulateLocationsDDL();

                        oResponse = View(viewModel);
                    }
                }
                else
                {
                    //Data call here to re-get the locations and producers.
                    //placed into method

                    viewModel.Shipment.ProducerDDL = PopulateProducersDDL();
                    viewModel.Shipment.LocationDDL = PopulateLocationsDDL();

                    oResponse = View(viewModel);
                }
            }
            else
            {
                oResponse = RedirectToAction("Login", "User");
            }
            return(oResponse);
        }
        public ActionResult UpdateShipment(ShipmentVM changeshipment)
        {
            ActionResult oResult = null;

            if (Session["UserName"] != null && (int)Session["UserLevel"] <= 2)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        IShipmentInfoDO updateShipment = ShipmentMap.MapPOtoDO(changeshipment.Shipment);
                        //call method from DAL to change the info in db
                        _ShipmentAccess.UpdateShipment(updateShipment);
                    }
                    catch (Exception e)
                    {
                        //what to do with exception what to write

                        if (e.Message.Contains("duplicate"))
                        {
                            changeshipment.ErrorMessage = "Unable to process request, duplicate record already exists";
                        }
                        else
                        {
                            changeshipment.ErrorMessage = "We apologize but we were unable to handle your request at this time.";
                        }
                    }
                    finally
                    {
                    }

                    if (changeshipment.ErrorMessage == null)
                    {
                        //if no errors with update, return to list of shipments to see if info was changed
                        oResult = RedirectToAction("ViewShipments", "Shipment");
                    }
                    else
                    {
                        oResult = RedirectToAction("UpdateShipment", "Shipment");
                    }
                }
                else
                {
                    oResult = View(changeshipment);
                }
            }
            else
            {
                oResult = RedirectToAction("Login", "User");
            }
            return(oResult);
        }
        public ActionResult ViewProducers()
        {
            //instantiate new viewmodel obj.
            ProducerVM newVM = new ProducerVM();

            //make sure user is authorized to add producer
            if (Session["UserName"] == null || (int)Session["UserLevel"] == 3)
            {
                RedirectToAction("Login", "User");
            }
            else
            {
                //instantiated new viewmodel, fill below
                try
                {
                    //call to DAL for method, reader fills list in method
                    List <IProducerInfoDO> ProducerData = _ProducerAccess.ViewAllProducers();
                    //call to method from mapping class
                    newVM.ProducerList = ProducerMap.MapDOtoPO(ProducerData);


                    //get a fresh list of shipments
                    List <IShipmentInfoDO> mylist = _ShipmentAccess.ViewAllShipments();
                    //Map each from DO to a BO
                    List <IShipmentInfoBO> viewTop = ShipmentMap.MapDOtoBO(mylist);
                    //call to the business logic, pass the information.
                    long topProducerID = _ShipmentLogic.GetTopProducer(viewTop);
                    //turn id into an object by calling down to the database, map in line.
                    newVM.Producer = ProducerMap.MapDOtoPO(_ProducerAccess.ViewProducerByID(topProducerID));
                    //now top producer is in PO form, can display using producerVM
                }
                catch (Exception)
                {
                    newVM.ErrorMessage = "There was an issue obtaining the list";
                }
                finally
                {
                    ///nothing else needs to happen
                }
            }


            return(View(newVM));
        }
        public ActionResult UpdateShipment(long ShipmentID)
        {
            ShipmentVM updateVM = new ShipmentVM();

            if (Session["UserName"] != null && (int)Session["UserLevel"] <= 2)
            {
                IShipmentInfoDO shipment = _ShipmentAccess.ViewShipmentByID(ShipmentID);

                updateVM.Shipment = ShipmentMap.MapDOtoPO(shipment);
                //call to data layer method to get list of producers for drop down
                updateVM.Shipment.LocationDDL = PopulateLocationsDDL();
                updateVM.Shipment.ProducerDDL = PopulateProducersDDL();
            }
            else
            {
                RedirectToAction("Login", "User");
            }

            return(View(updateVM));
        }
Beispiel #7
0
        /// <summary>
        /// Saves the state of to view.
        /// </summary>
        /// <param name="item">The item.</param>
        private void SaveToViewState(GridEditableItem item)
        {
            var invoiceShipment = new ShipmentMap();

            invoiceShipment.ID = ((DictionaryOnDemandComboBox)item.FindControl("dcbShipments")).SelectedId;

            var shipment = _dataManager.Shipment.SelectById(invoiceShipment.ID);

            invoiceShipment.CreatedAt      = shipment.CreatedAt;
            invoiceShipment.ShipmentTypeID = shipment.ShipmentTypeID;
            invoiceShipment.Note           = shipment.Note;
            invoiceShipment.Number         = shipment.Number;

            if (InvoiceShipmentsList.SingleOrDefault(o => o.ID == invoiceShipment.ID) == null)
            {
                InvoiceShipmentsList.Add(invoiceShipment);
            }

            if (InvoiceShipmentsChanged != null)
            {
                InvoiceShipmentsChanged(this, new EventArgs());
            }
        }