public HttpResponseMessage AddCarType([FromBody] CarTypeModel carTypeModel) { using (logic = new CarTypeManager()) { try { //בדיקה האם הפרמטר שעבר לפונקציה בתור מודל עומד בדרישות הואלידציה //BOהגדרות הואלידציה מוגדרות בתוך ה //Data annotation בתור if (!ModelState.IsValid) { string error = ModelState.Where(ms => ms.Value.Errors.Any()).Select(ms => ms.Value.Errors[0].ErrorMessage).FirstOrDefault(); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, error)); } // הולידציה עברה בהצלחה carTypeModel = logic.AddCarType(carTypeModel); return(Request.CreateResponse(HttpStatusCode.Created, carTypeModel)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionHelper.GetInnerMessage(ex))); } } }
// GET: api/Author public HttpResponseMessage Get() { return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <CarTypeModel[]>(CarTypeManager.SelectAllCarTypes(), new JsonMediaTypeFormatter()) }); }
// DELETE: api/CarTypes/5 public HttpResponseMessage Delete(string cartypemodel) { bool Result = CarTypeManager.DeleteCartype(cartypemodel); HttpStatusCode responsCode = Result ? HttpStatusCode.OK : HttpStatusCode.BadRequest; return(new HttpResponseMessage(responsCode) { Content = new ObjectContent <bool>(Result, new JsonMediaTypeFormatter()) }); }
// GET: api/CarTypes public HttpResponseMessage Get() { CarTypeModel[] CarTypesArry = CarTypeManager.GetAllCarTypes(); if (CarTypesArry == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <CarTypeModel[]>(CarTypesArry, new JsonMediaTypeFormatter()) }); }
// GET: api/CarTypes/5 public HttpResponseMessage Get(string cartypemodel) { CarTypeModel Singletype = CarTypeManager.GetSpesificCartype(cartypemodel); if (Singletype == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <CarTypeModel>(Singletype, new JsonMediaTypeFormatter()) }); }
// POST: api/CarTypes public HttpResponseMessage Post([FromBody] CarTypeModel value) { bool InsertResult = false; if (ModelState.IsValid) { InsertResult = CarTypeManager.AddNewCartype(value); } HttpStatusCode ResponsCode = InsertResult ? HttpStatusCode.Created : HttpStatusCode.BadRequest; return(new HttpResponseMessage(ResponsCode) { Content = new ObjectContent <bool>(InsertResult, new JsonMediaTypeFormatter()) }); }
public HttpResponseMessage DeleteCarType([FromUri] int id) { using (logic = new CarTypeManager()) { try { bool isDelete = logic.DeleteCarType(id); return(Request.CreateResponse(HttpStatusCode.OK, isDelete)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionHelper.GetInnerMessage(ex))); } } }
// GET: api/Author/5 public HttpResponseMessage Get(string carModel) { CarTypeModel carType = CarTypeManager.SelectCarTypeByModel(carModel); if (carType != null) { return new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <CarTypeModel>(carType, new JsonMediaTypeFormatter()) } } ; return(new HttpResponseMessage(HttpStatusCode.BadRequest)); }
public HttpResponseMessage GetOneCarType([FromUri] int CarTypeID) { using (logic = new CarTypeManager()) { try { CarTypeModel CarType = logic.GetOneCarType(CarTypeID); return(Request.CreateResponse(HttpStatusCode.OK, CarType)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionHelper.GetInnerMessage(ex))); } } }
[Route("all")] // access link : http://localhost:53093/api/order/orders public HttpResponseMessage GetAllCarTypes() { using (logic = new CarTypeManager()) { try { List <CarTypeModel> CarTypes = logic.GetAllCarTypes(); return(Request.CreateResponse(HttpStatusCode.OK, CarTypes)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionHelper.GetInnerMessage(ex))); } } }
// PUT: api/CarTypes/5 public HttpResponseMessage Put(string cartypemodel, [FromBody] CarTypeModel value) { bool updateResult = false; if (ModelState.IsValid) { updateResult = CarTypeManager.EditCarType(cartypemodel, value); } HttpStatusCode rsponseCode = (updateResult) ? HttpStatusCode.OK : HttpStatusCode.BadRequest; return(new HttpResponseMessage(rsponseCode) { Content = new ObjectContent <bool>(updateResult, new JsonMediaTypeFormatter()) }); }
// POST: api/Author public HttpResponseMessage Post([FromBody] CarTypeModel value) { bool insertResult = false; //ModelState is the parameter that we got to the Post function (value in our case) if (ModelState.IsValid) { insertResult = CarTypeManager.InsertCarType(value); } HttpStatusCode responseCode = insertResult ? HttpStatusCode.Created : HttpStatusCode.BadRequest; return(new HttpResponseMessage(responseCode) { Content = new ObjectContent <bool>(insertResult, new JsonMediaTypeFormatter()) }); }
// PUT: api/Author/5 public HttpResponseMessage Put(string carModel, [FromBody] CarTypeModel value) { bool updateResult = false; //ModelState is the parameter that we got to the Post function (value in our case) if (ModelState.IsValid) { updateResult = CarTypeManager.UpdateCarTypeByModel(carModel, value); } HttpStatusCode responseCode = updateResult ? HttpStatusCode.OK : HttpStatusCode.BadRequest; return(new HttpResponseMessage(responseCode) { Content = new ObjectContent <bool>(updateResult, new JsonMediaTypeFormatter()) }); }
static void Main(string[] args) { CarManager carManager = new CarManager(new EfCarDal()); BrandManager brandManager = new BrandManager(new EfBrandDal()); ColorManager colorManager = new ColorManager(new EfColorDal()); CarTypeManager carTypeManager = new CarTypeManager(new EfCarTypeDal()); UserManager userManager = new UserManager(new EfUserDal()); CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); IndividualCustomerManager individualCustomerManager = new IndividualCustomerManager(new EfIndividualCustomerDal()); CorporateCustomerManager corporateCustomerManager = new CorporateCustomerManager(new EfCorporateCustomerDal()); RentalManager rentalManager = new RentalManager(new EfRentalDal()); //AddDefaultData(carManager, brandManager, colorManager, carTypeManager); //AddIndividualCustomer(individualCustomerManager); //AddCorporateCustomer(corporateCustomerManager); //AddRental(carManager, rentalManager); }
static void Main(string[] args) { CarManager carManager = new CarManager(new EfCarDal()); BrandManager brandManager = new BrandManager(new EfBrandDal()); ColorManager colorManager = new ColorManager(new EfColorDal()); CarTypeManager carTypeManager = new CarTypeManager(new EfCarTypeDal()); DepartmentManager departmentManager = new DepartmentManager(new EfDepartmentDal()); UserManager userManager = new UserManager(new EfUserDal()); CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); IndividualCustomerManager individualCustomerManager = new IndividualCustomerManager(new EfIndividualCustomerDal()); EmployeeManager employeeManager = new EmployeeManager(new EfEmployeeDal()); RentalManager rentalManager = new RentalManager(new EfRentalDal()); //AddDefaultData(carManager, brandManager, colorManager, carTypeManager, departmentManager); //AddEmployee(employeeManager); //AddIndividualCustomer(individualCustomerManager); }
protected void ddlCarMark_SelectedIndexChanged(object sender, EventArgs e) { string name = "0"; name = Request.QueryString["DR_name"]; int id = Convert.ToInt32(ddlCarMark.SelectedValue); if (id != 0) { Car_Cars car = CarsManager.GetAllCarsById(id); Car_Type cartype = (Car_Type)CarTypeManager.GetAllCarsById(car.Typeid.TypeId); rblDR_CarType.SelectedValue = cartype.Genre; if (name == "Up") { rblDR_CarType.Enabled = false; } } else { rblDR_CarType.SelectedValue = "普通用车"; } }
public HttpResponseMessage UpdateCarType([FromBody] CarTypeModel CarTypeModel, [FromUri] int CarTypeID) { using (logic = new CarTypeManager()) { try { if (!ModelState.IsValid) { string error = ModelState.Where(ms => ms.Value.Errors.Any()).Select(ms => ms.Value.Errors[0].ErrorMessage).FirstOrDefault(); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, error)); } CarTypeModel = logic.UpdateCarType(CarTypeModel, CarTypeID); return(Request.CreateResponse(HttpStatusCode.OK, CarTypeModel)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionHelper.GetInnerMessage(ex))); } } }
private static void AddDefaultData(CarManager carManager, BrandManager brandManager, ColorManager colorManager, CarTypeManager carTypeManager, DepartmentManager departmentManager) { var brand = new Brand { Name = "Ford" }; brandManager.Add(brand); var color = new Color { Name = "Siyah" }; colorManager.Add(color); var carType = new CarType { Name = "Hatchback" }; carTypeManager.Add(carType); var car = new Car { Model = "Fiesta", ModelYear = "2012", ColorId = 1, BrandId = 1, CarTypeId = 1, Capacity = 4, DailyPrice = 100, }; carManager.Add(car); var department = new Department { Name = "Satış" }; departmentManager.Add(department); }