Пример #1
0
        public IHttpActionResult Update(Rancher rancher)
        {
            RancherResponse response = new RancherResponse();

            try
            {
                Rancher rancherSaved = rancherBL.UpdateRancher(rancher);
                response.Rancher = rancherSaved;
                response.Success = true;
            }
            catch (RancherException ex)
            {
                response.ErrorCode    = ex.Error;
                response.ErrorMessage = "Error. " + ex.Error.ToString();
                response.Rancher      = null;
                response.Success      = false;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = "Error. " + ex.Message;
                response.Rancher      = null;
                response.Success      = false;
            }
            return(Ok(response));
        }
Пример #2
0
 public RancherList()
 {
     InitializeComponent();
     presenter      = new RancherPresenter(this);
     CurrentRancher = new Rancher();
     GridRancherDetails.DataContext = CurrentRancher;
 }
Пример #3
0
        public static List <Rancher> GetRanchers()
        {
            List <Rancher> ranchers = new List <Rancher>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand("SELECT * FROM gan_Proveedores"))
                {
                    command.Connection = connection;
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Rancher rancher = new Rancher();
                            rancher.Name    = reader["Nombre"].ToString();
                            rancher.Address = reader["direccion"].ToString();
                            rancher.City    = reader["ciudad"].ToString();
                            rancher.StateId = int.Parse(reader["estadoID"].ToString());
                            rancher.RFC     = reader["RFC"].ToString();
                            ranchers.Add(rancher);
                        }
                    }
                }
            }
            return(ranchers);
        }
Пример #4
0
        public static Rancher  CreateDummyRancher()
        {
            Rancher rancher = new Rancher();

            rancher.Address = "TestAddres1";
            rancher.Name    = "RancherTestName";
            return(rancher);
        }
Пример #5
0
        public Rancher UpdateRancher(Rancher rancher)
        {
            //Add validations here!
            RancherError result = RancherError.None;

            if (string.IsNullOrEmpty(rancher.Name))
            {
                result |= RancherError.InvalidName;
            }
            if (rancher.StateId <= 0)
            {
                result |= RancherError.InvalidState;
            }
            if (result != RancherError.None)
            {
                throw new RancherException(result);
            }
            else
            {
                return(rancherDL.UpdateRancher(rancher));
            }
        }
Пример #6
0
 public Rancher UpdateRancher(Rancher rancher)
 {
     using (SqlCommand command = new SqlCommand())
     {
         using (SqlConnection connection = new SqlConnection())
         {
             connection.ConnectionString = ConnectionString;
             command.Connection          = connection;
             command.CommandText         = "spUpsertRancher";
             command.CommandType         = CommandType.StoredProcedure;
             foreach (PropertyInfo prop in (from x in rancher.GetType().GetProperties() where !excludedPropertiesInUpdate.Contains(x.Name) select x).ToArray())
             {
                 command.Parameters.AddWithValue("@" + prop.Name, prop.GetValue(rancher));
             }
             connection.Open();
             object rancherId = command.ExecuteScalar();
             rancher.Id = int.Parse(rancherId.ToString());
             connection.Close();
         }
         return(rancher);
     }
 }