Exemple #1
0
 /// <summary>
 /// Called from PUT
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="returnMessage"></param>
 /// <returns></returns>
 public bool Update(orders obj, out string returnMessage)
 {
     returnMessage = string.Empty;
     using (var edc = new EDC())
     {
         edc.Entry(obj).State = System.Data.Entity.EntityState.Modified;
         try
         {
             edc.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             returnMessage = ex.Message;
             return(false);
         }
     }
 }
        public static List <orders> GetValidOrder()
        {
            List <orders> o = new List <orders>();

            IDbConnection conn = new MySqlConnection();

            conn.ConnectionString = connString;
            string     query = " select * from orders where ordered_date > curdate() - 10";
            IDbCommand cmd   = new MySqlCommand();

            cmd.CommandText = query;
            cmd.Connection  = conn;
            MySqlDataAdapter da = new MySqlDataAdapter(cmd as MySqlCommand);
            DataSet          ds = new DataSet();

            try
            {
                //orderid, customerID, cropID, quantity, total_amount

                da.Fill(ds);
                DataRowCollection rows = ds.Tables[0].Rows;
                foreach (DataRow row in rows)
                {
                    orders order = new orders();
                    order.orderid      = int.Parse(row["orderid"].ToString());
                    order.customerID   = int.Parse(row["customerID"].ToString());
                    order.cropID       = int.Parse(row["cropID"].ToString());
                    order.quantity     = int.Parse(row["quantity"].ToString());
                    order.total_amount = int.Parse(row["total_amount"].ToString());
                    order.crop_name    = row["crop_name"].ToString();
                    order.address      = row["address"].ToString();
                    order.ordered_date = DateTime.Parse(row["ordered_date"].ToString());
                    o.Add(order);
                }
            }
            catch (MySqlException e)
            {
                string message = e.Message;
            }
            // implementation
            return(o);
        }
Exemple #3
0
        /// <summary>
        /// Called from DELETE
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="returnMessage"></param>
        /// <returns></returns>
        public bool Delete(string id, out string returnMessage)
        {
            returnMessage = string.Empty;
            using (var edc = new EDC())
            {
                orders obj = Get(id);

                edc.Entry(obj).State = System.Data.Entity.EntityState.Deleted;
                try
                {
                    edc.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    returnMessage = ex.Message;
                    return(false);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Called from POST
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="returnMessage"></param>
        /// <returns></returns>
        public bool Create(orders obj, out string returnMessage)
        {
            Guid id = Guid.NewGuid();

            obj.id        = id.ToString();
            returnMessage = id.ToString();
            using (var edc = new EDC())
            {
                edc.Orders.Add(obj);
                try
                {
                    edc.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    returnMessage = ex.Message;
                    return(false);
                }
            }
        }