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
        //map producer data obj to producer presentation obj
        public static ProducerPO MapDOtoPO(IProducerInfoDO iFrom)
        {
            //instantiate new PO to fill
            ProducerPO newproducer = new ProducerPO();

            newproducer.ProducerID  = iFrom.ProducerID;
            newproducer.CompanyName = iFrom.CompanyName;
            newproducer.ContactName = iFrom.ContactName;
            newproducer.Address     = iFrom.Address;
            newproducer.Phone       = iFrom.Phone;

            return(newproducer);
        }
Ejemplo n.º 4
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.º 5
0
        public void InsertProducer(IProducerInfoDO producer)
        {
            try
            {
                //create connection
                using (SqlConnection connectionToSQL = new SqlConnection(connectionString))
                    //create a command
                    using (SqlCommand command = new SqlCommand("ADD_PRODUCER", connectionToSQL))
                    {
                        try
                        {
                            command.CommandType    = CommandType.StoredProcedure;
                            command.CommandTimeout = 35;
                            //values from form get pushed to fill SQL
                            command.Parameters.AddWithValue("@CompanyName", producer.CompanyName);
                            command.Parameters.AddWithValue("@ContactName", producer.ContactName);
                            command.Parameters.AddWithValue("@Phone", producer.Phone);
                            command.Parameters.AddWithValue("@Address", producer.Address);

                            connectionToSQL.Open();
                            command.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            //error wrote to file
                            ErrorLogging.LogError(e);
                            throw (e);
                        }
                        finally
                        {
                            //should close with using statement, finally is just to be sure
                            connectionToSQL.Close();
                            connectionToSQL.Dispose();
                        }
                    }
            }
            catch (Exception e)
            {
                ErrorLogging.LogError(e);
                throw (e);
            }
            finally
            {
                //no connection to dispose, do nothing
            }
        }
Ejemplo n.º 6
0
 public void UpdateProducer(IProducerInfoDO producer)
 {
     try
     {
         //create connection
         using (SqlConnection connectionToSQL = new SqlConnection(connectionString))
             //create a command to run Stored Proc
             using (SqlCommand command = new SqlCommand("UPDATE_PRODUCER", connectionToSQL))
             {
                 try
                 {
                     command.CommandType    = CommandType.StoredProcedure;
                     command.CommandTimeout = 35;
                     //fill new SQL row with this data
                     command.Parameters.AddWithValue("@ProducerID", producer.ProducerID);
                     command.Parameters.AddWithValue("@CompanyName", producer.CompanyName);
                     command.Parameters.AddWithValue("@ContactName", producer.ContactName);
                     command.Parameters.AddWithValue("@Phone", producer.Phone);
                     command.Parameters.AddWithValue("@Address", producer.Address);
                     //open SQL and run process this request
                     connectionToSQL.Open();
                     command.ExecuteNonQuery();
                 }
                 catch (Exception e)
                 {
                     ErrorLogging.LogError(e);
                     throw e;
                 }
                 finally
                 {
                 }
             }
     }
     catch (Exception e)
     {
         throw e;
     }
     finally
     {
         //nothing needs to happen on this finally, connections are closed and errors are logged and passed up the chain
     }
 }