コード例 #1
0
        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)));
                }
            }
        }
コード例 #2
0
 // GET: api/Author
 public HttpResponseMessage Get()
 {
     return(new HttpResponseMessage(HttpStatusCode.OK)
     {
         Content = new ObjectContent <CarTypeModel[]>(CarTypeManager.SelectAllCarTypes(), new JsonMediaTypeFormatter())
     });
 }
コード例 #3
0
        // 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())
            });
        }
コード例 #4
0
 // 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())
     });
 }
コード例 #5
0
        // 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())
            });
        }
コード例 #6
0
        // 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())
            });
        }
コード例 #7
0
 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)));
         }
     }
 }
コード例 #8
0
        // 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));
        }
コード例 #9
0
 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)));
         }
     }
 }
コード例 #10
0
 [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)));
         }
     }
 }
コード例 #11
0
        // 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())
            });
        }
コード例 #12
0
        // 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())
            });
        }
コード例 #13
0
        // 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())
            });
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: dnzhngl/RentACar-FullStack
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
    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 = "普通用车";
        }
    }
コード例 #17
0
        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)));
                }
            }
        }
コード例 #18
0
        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);
        }