Esempio n. 1
0
        public HttpResponseMessage Update(HttpRequestMessage request, EditCustomerViewModel customerVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    //Cập nhật thông tin khách hàng
                    var dbCust = _customerService.GetById(customerVm.IDCustomer);
                    dbCust.Name = customerVm.NameCustomer;
                    dbCust.PhoneNumber = customerVm.PhoneNumber;
                    dbCust.Email = customerVm.Email;
                    dbCust.Address = customerVm.Address;


                    _customerService.Update(dbCust);
                    _customerService.Save();

                    //Cập nhật lại Book
                    var dbBook = _bookService.GetById(customerVm.IDBook);
                    dbBook.IDCar = customerVm.IDCar;
                    dbBook.IDSeat = customerVm.IDSeat;
                    dbBook.IDSeatNo = customerVm.IDSeatNo;
                    dbBook.UpdatedBy = customerVm.UpdatedBy;
                    dbBook.UpdatedDate = DateTime.Now;
                    dbBook.MetaDescription = customerVm.MetaDescription;

                    _bookService.Update(dbBook);
                    _bookService.Save();

                    //Update lại status
                    var dbSeatNo = _seatnoService.GetById(customerVm.oldIDSeatNo);
                    dbSeatNo.Status = false;
                    _seatnoService.Update(dbSeatNo);
                    _seatnoService.Save();

                    var dbNewSeatNo = _seatnoService.GetById(customerVm.IDSeatNo);
                    dbNewSeatNo.Status = true;
                    _seatnoService.Update(dbNewSeatNo);
                    _seatnoService.Save();

                    var responseData = Mapper.Map <Customer, CustomerViewModel>(dbCust);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Esempio n. 2
0
        public HttpResponseMessage Create(HttpRequestMessage request, int idSeatNo)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    //update SeatNo
                    var dbSeatNo = _seatnoService.GetById(idSeatNo);
                    dbSeatNo.Status = false;
                    _seatnoService.Update(dbSeatNo);
                    _seatnoService.Save();

                    response = request.CreateResponse(HttpStatusCode.Created, dbSeatNo);
                }

                return response;
            }));
        }
Esempio n. 3
0
        public HttpResponseMessage Create(HttpRequestMessage request, CarViewModel carVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var crSeat = new Seat();
                    var crSeatNo = new SeatNo();
                    string[] seat = new string[] { "A", "B", "C", "D", "E", "G", "H", "I", "K" };

                    var newCar = new Car();
                    newCar.UpdateCar(carVm);
                    newCar.CreatedDate = DateTime.Now;

                    _carService.Add(newCar);
                    _carService.Save();

                    for (int i = 0; i < 9; i++)
                    {
                        crSeat.IDCar = newCar.ID;
                        crSeat.Row = seat[i];
                        crSeat.isDel = false;
                        _seatService.Add(crSeat);
                        _seatService.Save();


                        if (seat[i] == "K")     //Hàng cuối luôn 5 ghế
                        {
                            for (int n = 1; n <= 10; n++)
                            {
                                var date1 = DateTime.Now;
                                var date = date1.AddDays(n);
                                for (int j = 1; j < 6; j++)
                                {
                                    crSeatNo.IDSeat = crSeat.ID;
                                    crSeatNo.SeatNb = j;
                                    crSeatNo.Status = false;
                                    crSeatNo.DateBook = date;
                                    _seatnoService.Add(crSeatNo);
                                    _seatnoService.Save();
                                }
                            }
                        }

                        else     //Các hàng còn lại 4 ghế
                        {
                            for (int n = 1; n <= 10; n++)
                            {
                                var date1 = DateTime.Now;
                                var date = date1.AddDays(n);
                                for (int j = 1; j < 5; j++)
                                {
                                    crSeatNo.IDSeat = crSeat.ID;
                                    crSeatNo.SeatNb = j;
                                    crSeatNo.Status = false;
                                    crSeatNo.DateBook = date;
                                    _seatnoService.Add(crSeatNo);
                                    _seatnoService.Save();
                                }
                            }
                        }
                    }



                    var responseData = Mapper.Map <Car, CarViewModel>(newCar);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Esempio n. 4
0
        public HttpResponseMessage Create(HttpRequestMessage request, BookViewModel bookVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    //Thêm mới khách hàng
                    var newCustomer = new Customer();
                    newCustomer.Name = bookVm.NameCustomer;
                    newCustomer.PhoneNumber = bookVm.PhoneCustomer;
                    newCustomer.Email = bookVm.MailCustomer;
                    newCustomer.Address = bookVm.AddressCustomer;
                    newCustomer.isDel = false;
                    //AddCustommer
                    _customerService.Add(newCustomer);
                    _customerService.Save();



                    //Thêm mới book
                    var newBook = new Booking();
                    newBook.IDCar = bookVm.IDCar;
                    newBook.IDCustomer = newCustomer.ID;
                    newBook.IDSeat = bookVm.IDSeat;
                    newBook.IDSeatNo = bookVm.IDSeatNo;
                    newBook.DateBook = DateTime.Now;
                    newBook.CreatedBy = bookVm.CreatedBy;
                    newBook.CreatedDate = DateTime.Now;
                    newBook.MetaDescription = bookVm.MetaDescription;
                    newBook.Status = true;
                    //AddBoook
                    _bookService.Add(newBook);
                    _bookService.Save();


                    //NewBill
                    var newBill = new Bill();
                    newBill.CustomerName = bookVm.NameCustomer;
                    newBill.CustomerPhone = bookVm.PhoneCustomer;
                    newBill.dateBook = bookVm.Date;
                    newBill.DatedBill = DateTime.Now;
                    newBill.IDCar = bookVm.IDCar;
                    newBill.SeatName = bookVm.SeatNoName;
                    newBill.CountMoney = "210000";
                    newBill.CustomerMail = bookVm.MailCustomer;
                    newBill.Status = false;

                    //AddBill
                    _billService.Add(newBill);
                    _billService.Save();


                    //update SeatNo
                    var dbSeatNo = _seatnoService.GetById(bookVm.IDSeatNo);
                    dbSeatNo.Status = true;
                    _seatnoService.Update(dbSeatNo);
                    _seatnoService.Save();

                    var responseData = Mapper.Map <Customer, CustomerViewModel>(newCustomer);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }