public HttpResponseMessage Create(HttpRequestMessage request, ModelCommon ctkhachhang)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    ctkhachhang.KhachHang.CreatedDate = DateTime.Now;
                    var khachhang = _khachHangService.Add(ctkhachhang.KhachHang);
                    _khachHangService.SaveChange();

                    if (ctkhachhang.ChiTiet.NgayChuaBenh == DateTime.MinValue || ctkhachhang.ChiTiet.NgayChuaBenh == null)
                    {
                        ctkhachhang.ChiTiet.NgayChuaBenh = DateTime.Now;
                    }
                    ctkhachhang.ChiTiet.IdKhachHang = khachhang.Id;
                    var chitiet = _chitietKhachHangService.Add(ctkhachhang.ChiTiet);
                    _khachHangService.SaveChange();
                    response = request.CreateResponse(HttpStatusCode.OK, khachhang);
                }

                return response;
            }));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "TenKH,SDT,CMND,DiaChi,Email")] KHACHHANG KH, [Bind(Include = "GiaMua,MaChuyen,TramLen,TramXuong,GioDi,MaXe")] VE vE, string strGhe, string MaKH)
        {
            if (ModelState.IsValid)
            {
                if (strGhe != "")
                {
                    string[] dsGhe   = strGhe.Split(',');
                    int      maKHNew = -1;
                    if (MaKH == "")
                    {
                        KH.isDeleted = 0;
                        maKHNew      = khService.Add(KH);
                    }
                    else
                    {
                        maKHNew = int.Parse(MaKH);
                    }
                    DateTime current = DateTime.Now;
                    for (int i = 0; i < dsGhe.Length; i++)
                    {
                        vE.MaKH      = maKHNew;
                        vE.MaGhe     = int.Parse(dsGhe[i]);
                        vE.isDeleted = 0;
                        vE.NgayMua   = current;
                        service.Add(vE);
                    }
                }
                return(RedirectToAction("Index"));
            }

            return(View(vE));
        }
        public HttpResponseMessage Create(HttpRequestMessage request, KhachHangViewModel khachhang)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    bool result = CheckKhachHang(khachhang.Name);
                    if (result)
                    {
                        KhachHang NewKh = new KhachHang();
                        NewKh.UpdateKhachHang(khachhang);
                        var model = _khachHangService.Add(NewKh);
                        var mapper = Mapper.Map <KhachHang, KhachHangViewModel>(model);
                        _khachHangService.SaveChange();
                        response = request.CreateResponse(HttpStatusCode.OK, mapper);
                    }
                    else
                    {
                        response = request.CreateResponse(HttpStatusCode.BadRequest, "Tên không được trùng");
                    }
                }

                return response;
            }));
        }
Example #4
0
        public ActionResult Create([Bind(Include = "MaKH,TenKH,SDT,CMND,DiaChi,NgaySinh,Email,createUser,lastupdateUser,createDate,lastupdateDate,isDeleted")] KHACHHANG kHACHHANG)
        {
            if (ModelState.IsValid)
            {
                kHACHHANG.isDeleted = 0;
                service.Add(kHACHHANG);
                return(RedirectToAction("Index"));
            }

            return(View(kHACHHANG));
        }
        public HttpResponseMessage Created(HttpRequestMessage request, KhachHangViewModel khachHangVM)
        {
            return(CreateReponse(request, () => {
                HttpResponseMessage response;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(System.Net.HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var khachHang = new KhachHang();
                    khachHang.UpdateKhachHang(khachHangVM);
                    _ikhachHangService.Add(khachHang);
                    _ikhachHangService.save();
                    response = request.CreateResponse(System.Net.HttpStatusCode.Created, khachHang);
                }

                return response;
            }));
        }