public JsonResult Create(string room_name, string category_room, int price_room) { Room room = new Room { RoomID = RandomString.getRandomString(5), RoomName = room_name.ToString(), CategoryRoomID = category_room.ToString(), RoomPrice = decimal.Parse(price_room.ToString()), Status = false }; var create = _dbContext.Rooms.Add(room); if (create != null) { try { _dbContext.SaveChanges(); return(Json(new { data = "Thêm thành công", status = true }, JsonRequestBehavior.AllowGet)); } catch (DbEntityValidationException e) { return(Json(new { data = e.Message, status = false }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { data = "Thêm thất bại", status = false }, JsonRequestBehavior.AllowGet)); } }
public JsonResult Create(string categoryName, int numberOfGuest) { CategoryRoom categoryRoom = new CategoryRoom { CategoryRoomID = RandomString.getRandomString(5), CategoryRoomName = categoryName, NumberOfGuest = numberOfGuest }; var create = _dbContext.CategoryRooms.Add(categoryRoom); if (create != null) { try { _dbContext.SaveChanges(); return(Json(new { data = "Thêm thành công", status = true }, JsonRequestBehavior.AllowGet)); } catch (DbEntityValidationException e) { return(Json(new { data = e.Message, status = false }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { data = "Thêm thất bại", status = false }, JsonRequestBehavior.AllowGet)); } }
public JsonResult Register(string username, string password, string email, string address, string cellphone) { var check_email = _dbContext.Customers.Where(x => x.CustomerEmail == email).FirstOrDefault(); if (check_email == null) { string hash_password = StringHash.crypto(password); Customer customer = new Customer { CustomerID = RandomString.getRandomString(5), CustomerName = username, CustomerPassword = hash_password, CustomerEmail = email, CustomerAddress = address, CustomerCellphone = cellphone }; var register = _dbContext.Customers.Add(customer); if (register != null) { _dbContext.SaveChanges(); return(Json(new { data = "Đăng ký thành công", status = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { data = "Đăng ký thất bại", status = false }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { data = "Email đã tồn tại, vui lòng nhập lại", status = false }, JsonRequestBehavior.AllowGet)); } }
public JsonResult UpdateCustomer(string address, string cellphone) { string customerID = (string)Session["CustomerID"]; var updateCustomer = _dbContext.Customers.Where(x => x.CustomerID == customerID).FirstOrDefault(); if (updateCustomer != null) { updateCustomer.CustomerAddress = address; updateCustomer.CustomerCellphone = cellphone; _dbContext.SaveChanges(); return(Json(new { data = "Cập nhật thành công", status = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { data = "Cập nhật thất bại", status = false }, JsonRequestBehavior.AllowGet)); } }
public JsonResult ChangePassword(string old_password, string new_password) { string hash_password = StringHash.crypto(old_password); string adminID = (string)Session["AdminID"]; var updatePasswordAdmin = _dbContext.Admins.Where(x => x.ID == adminID && x.Password == hash_password).FirstOrDefault(); if (updatePasswordAdmin != null) { string hash_new_password = StringHash.crypto(new_password); updatePasswordAdmin.Password = hash_new_password; _dbContext.SaveChanges(); return(Json(new { data = "Đổi mật khẩu thành công", status = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { data = "Mật khẩu cũ không chính xác", status = false }, JsonRequestBehavior.AllowGet)); } }
public JsonResult approveOrder(string id) { var dataOrder = _dbContext.Orders.Where(x => x.OrderID == id).FirstOrDefault(); if (dataOrder != null) { string roomID = dataOrder.RoomID; var dataRoom = _dbContext.Rooms.Where(x => x.RoomID == roomID).FirstOrDefault(); dataOrder.Status = true; dataRoom.Status = true; _dbContext.SaveChanges(); return(Json(new { data = "Duyệt đơn thành công", status = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { data = "Duyệt đơn không thành công", status = false }, JsonRequestBehavior.AllowGet)); } }
public JsonResult SubmitBook(string fullname, string email, string category_room, string room, DateTime received_date, DateTime checkout_date, int numberofguest) { decimal price = _dbContext.Rooms.Where(x => x.RoomID == room).FirstOrDefault().RoomPrice; if (received_date < DateTime.Now && checkout_date <= DateTime.Now) { return(Json(new { data = "Thời gian không hợp lệ.", status = false }, JsonRequestBehavior.AllowGet)); } else { string customerID = Session["CustomerID"] as string; Order order = new Order { OrderID = RandomString.getRandomString(5), CustomerID = (customerID != null) ? customerID : RandomString.getRandomString(5), RoomID = room, Email = email, ReceivedDate = received_date, CheckOutDate = checkout_date, NumberGuest = numberofguest, Amount = price, Status = false }; var create = _dbContext.Orders.Add(order); if (create != null) { _dbContext.SaveChanges(); return(Json(new { data = "Đặt phòng thành công, vui lòng kiểm tra Mail", status = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { data = "Có lỗi xảy ra, vui lòng đợi", status = false }, JsonRequestBehavior.AllowGet)); } } }