public UserCheckoutModel OrderDetails(int user_id) { string query = "SELECT order_number,total_prise FROM public.rm_userchekout WHERE user_id=@user_id"; con.Open(); cmd = new NpgsqlCommand(query, con); cmd.Parameters.AddWithValue("@user_id", user_id); UserCheckoutModel model = new UserCheckoutModel(); try { NpgsqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { model.order_number = Convert.ToInt32(dr["order_number"]); model.total_prise = Convert.ToInt32(dr["total_prise"]); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { con.Close(); } return(model); }
public List <UserCheckoutModel> ImageSell() { List <UserCheckoutModel> mod = new List <UserCheckoutModel>(); string query = "select total_prise,ship_date from rm_userchekout"; con.Open(); cmd = new NpgsqlCommand(query, con); try { NpgsqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { UserCheckoutModel model = new UserCheckoutModel(); model.total_prise = Convert.ToInt32(dr["total_prise"]); model.ship_date = Convert.ToDateTime(dr["ship_date"]); mod.Add(model); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { con.Close(); } return(mod); }
public ActionResult CheckoutDetail() { int id = userRepo.GetUserId(User.Identity.Name); UserCheckoutModel mod = new UserCheckoutModel(); mod = cartRepo.OrderDetails(id); ViewBag.order_number = mod.order_number; ViewBag.total = mod.total_prise; return(View()); }
public ActionResult Checkout(UserCheckoutModel model) { Random rnd = new Random(); model.order_number = GenerateRandomInt(rnd); model.user_id = userRepo.GetUserId(User.Identity.Name); model.cart_id = cartRepo.getCartId(model.user_id); model.total_prise = photorepo.totalPrise(User.Identity.Name); int i = cartRepo.CheckOut(model); if (i >= 1) { cartRepo.DeleteAllCartItem(model.user_id); return(RedirectToAction("CheckoutDetail")); } else { return(RedirectToAction("Index")); } }
public int CheckOut(UserCheckoutModel model) { string query = "INSERT INTO public.rm_userchekout(first_name,last_name,address,state,postalcode,country,phone,email,ship_date,total_prise,user_id,order_number) VALUES(@first_name,@last_name,@address,@state,@postalcode,@country,@phone,@email,@ship_date,@total_prise,@user_id,@order_number)"; con.Open(); DateTime date = Convert.ToDateTime(model.ship_date); cmd = new NpgsqlCommand(query, con); cmd.Parameters.AddWithValue("@first_name", model.first_name); cmd.Parameters.AddWithValue("@last_name", model.last_name); cmd.Parameters.AddWithValue("@address", model.address); cmd.Parameters.AddWithValue("@state", model.state); cmd.Parameters.AddWithValue("@postalcode", model.postalcode); cmd.Parameters.AddWithValue("@country", model.country); cmd.Parameters.AddWithValue("@phone", model.phone); cmd.Parameters.AddWithValue("@email", model.email); cmd.Parameters.AddWithValue("@ship_date", date); cmd.Parameters.AddWithValue("@total_prise", model.total_prise); cmd.Parameters.AddWithValue("@user_id", model.user_id); //cmd.Parameters.AddWithValue("@cart_id", model.cart_id); cmd.Parameters.AddWithValue("@order_number", model.order_number); int i = 0; try { i = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { con.Close(); } return(i); }