Ejemplo n.º 1
0
        public ActionResult UpdateProducer(long ProducerID)
        {
            ProducerVM      updateVM = new ProducerVM();
            IProducerInfoDO producer = _ProducerAccess.ViewProducerByID(ProducerID);

            updateVM.Producer = ProducerMap.MapDOtoPO(producer);

            return(View(updateVM));
        }
Ejemplo n.º 2
0
        public ActionResult UpdateProducer(ProducerVM changeproducer)
        {
            ActionResult oResult = null;

            if (Session["UserName"] == null || ((int)Session["UserLevel"] > 2))
            {
                RedirectToAction("Login", "User");
            }
            else
            {
                //if the info was entered as required
                if (ModelState.IsValid)
                {
                    try
                    {
                        IProducerInfoDO updateProducer = ProducerMap.MapPOtoDO(changeproducer.Producer);
                        //call to producer data access method
                        _ProducerAccess.UpdateProducer(updateProducer);
                    }
                    catch (Exception e)
                    {
                        //what to do with exception, what to write

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

                    if (changeproducer.ErrorMessage == null)
                    {
                        //if no errors take them to producer list to see if their submission was added
                        oResult = RedirectToAction("ViewProducers", "Producer");
                    }
                    else
                    {
                        //if any errors caught then redirect to screen to change producer info, same as they came from
                        oResult = View(changeproducer);
                    }
                }
                else
                {
                    oResult = View(changeproducer);
                }
            }
            return(oResult);
        }
Ejemplo n.º 3
0
        public ActionResult AddProducer(ProducerVM viewModel)
        {
            ActionResult oResponse = null;

            if (Session["UserName"] == null || (int)Session["UserLevel"] > 2)
            {
                oResponse = RedirectToAction("Login", "User");
            }
            else
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        IProducerInfoDO locationform = ProducerMap.MapPOtoDO(viewModel.Producer);
                        _ProducerAccess.InsertProducer(locationform);
                    }
                    catch (Exception e)
                    {
                        if (e.Message.Contains("duplicate"))
                        {
                            //if that Company name is already in the DB, push this message to user
                            viewModel.ErrorMessage = String.Format("There is already a {0} in the database.", viewModel.Producer.CompanyName);
                        }
                        else
                        {
                            //other errors thatn duplicate
                            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("ViewProducers", "Producer");
                    }
                    else
                    {
                        oResponse = View(viewModel);
                    }
                }
                else
                {
                    oResponse = View(viewModel);
                }
            }
            return(oResponse);
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        private SelectList PopulateProducersDDL()
        {
            //for entereing shipments, need to know it is coming from a farmer in the db!
            List <IProducerInfoDO> databaseProducers = _ProducerAccess.ViewAllProducers();

            //map
            List <ProducerPO> mappedProducers = ProducerMap.MapDOtoPO(databaseProducers);
            List <ProducerPO> actualList      = new List <ProducerPO>();

            //add dummy location for "default" on dropdown, otherwise it sets to ACTUAL location
            actualList.Add(new ProducerPO()
            {
                ProducerID = 0, CompanyName = " -- Please choose a Producer --"
            });

            //after dummy is in top stop, add range from db
            actualList.AddRange(mappedProducers);

            //producer id what is listed, user will see label as Company Name
            return(new SelectList(actualList, "ProducerID", "CompanyName"));
        }