Ejemplo n.º 1
0
 public DeliveryStatuDTO UpdateDeliveryStatus(DeliveryStatuDTO delStatus)
 {
     using (var entities = new TradingCompanyEntities())
     {
         entities.DeliveryStatus.AddOrUpdate(_mapper.Map <DeliveryStatu>(delStatus));
         var dstatus = entities.DeliveryStatus.Single(ds => ds.DeliveryStatusID == delStatus.DeliveryStatusID);
         entities.SaveChanges();
         return(_mapper.Map <DeliveryStatuDTO>(dstatus));
     }
 }
Ejemplo n.º 2
0
 public DeliveryStatuDTO CreateDeliveryStatus(DeliveryStatuDTO delStatus)
 {
     using (var entities = new TradingCompanyEntities())
     {
         DeliveryStatu ds = _mapper.Map <DeliveryStatu>(delStatus);
         entities.DeliveryStatus.Add(ds);
         entities.SaveChanges();
         return(_mapper.Map <DeliveryStatuDTO>(ds));
     }
 }
Ejemplo n.º 3
0
        private void update()
        {
            Console.WriteLine("Input DeliveryStatusID: ");
            short id = Convert.ToInt16(Console.ReadLine());

            DeliveryStatuDTO ds = dal.GetDelStatusById(id);


            bool flag = true;

            while (flag)
            {
                Console.WriteLine("~ Updating Item:\n\tID: {0}\n\tStatus: {1} ",
                                  ds.DeliveryStatusID, ds.Status);
                Console.WriteLine("Choose an option:" +
                                  "\n\t1. Change status name" +
                                  "\n\t0. Exit");
                try
                {
                    int opt = Convert.ToInt32(Console.ReadLine());
                    if (opt == 0)
                    {
                        flag = false;
                    }
                    switch (opt)
                    {
                    case 1:
                        Console.WriteLine("Input new Status name: ");
                        string st = Console.ReadLine();
                        ds.Status = st;
                        break;

                    case 0:
                        flag = false;
                        break;

                    default:
                        throw new Exception("Invalid input.");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Console.WriteLine("Try again, or input 0 to exit.");
                }
                ds = dal.UpdateDeliveryStatus(ds);
                Console.WriteLine("Updated Status:\n\tID: {0}\n\tStatus: {1} ", ds.DeliveryStatusID, ds.Status);
                printAll();
            }
        }
Ejemplo n.º 4
0
        public DeliveryStatuDTO UpdateDeliveryStatus(DeliveryStatuDTO delStatus)
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
                using (SqlCommand comm = conn.CreateCommand())
                {
                    comm.CommandText = "UPDATE DeliveryStatus set Status = @status";
                    comm.Parameters.Clear();
                    comm.Parameters.AddWithValue("@status", delStatus.Status);
                    conn.Open();

                    delStatus.DeliveryStatusID = Convert.ToInt16(comm.ExecuteScalar());
                    return(delStatus);
                }
        }
Ejemplo n.º 5
0
        private void create()
        {
            Console.WriteLine("\t~*~ ~*~ ~*~ \tCreating New Delivery Status\t ~*~ ~*~ ~*~\n");
            Console.WriteLine("Input new status name: ");
            string _status = Console.ReadLine();

            DeliveryStatuDTO myStatus = new DeliveryStatuDTO
            {
                Status = _status
            };

            myStatus = dal.CreateDeliveryStatus(myStatus);
            Console.WriteLine($"New DeliveryStatusID is {myStatus.DeliveryStatusID}");
            printAll();
        }
Ejemplo n.º 6
0
        public DeliveryStatuDTO CreateDeliveryStatus(DeliveryStatuDTO delStatus)
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
                using (SqlCommand comm = conn.CreateCommand())
                {
                    comm.CommandText = "INSERT into DeliveryStatus (Status) output INSERTED.DeliveryStatusID values (@status)";
                    comm.Parameters.Clear();

                    comm.Parameters.AddWithValue("@status", delStatus.Status);

                    conn.Open();
                    delStatus.DeliveryStatusID = Convert.ToInt16(comm.ExecuteScalar());
                    return(delStatus);
                }
        }
Ejemplo n.º 7
0
 public DeliveryStatuDTO GetDelStatusById(short id)
 {
     using (SqlConnection conn = new SqlConnection(this.connectionString))
         using (SqlCommand comm = conn.CreateCommand())
         {
             conn.Open();
             DeliveryStatuDTO delStatus = new DeliveryStatuDTO();
             comm.CommandText = $"SELECT * from DeliveryStatus WHERE DeliveryStatusID = {id}";
             SqlDataReader reader = comm.ExecuteReader();
             while (reader.Read())
             {
                 delStatus = new DeliveryStatuDTO
                 {
                     DeliveryStatusID = (short)reader["DeliveryStatusID"],
                     Status           = reader["Status"].ToString()
                 };
             }
             return(delStatus);
         }
 }