Ejemplo n.º 1
0
 public IActionResult Create(KhachHangDTO khachhangDTO)
 {
     if (ModelState.IsValid)
     {
         khachhangDTO.Id = 0;
         khachhangService.Create(khachhangDTO);
         return(RedirectToAction("Index"));
     }
     return(View(khachhangDTO));
 }
 public IActionResult Register(RegisterNguoiDung nguoiDung)
 {
     if (ModelState.IsValid)
     {
         if (khachHangService.CheckTaiKhoan(nguoiDung.TaiKhoan))
         {
             ViewBag.TB = "Tên Đăng Nhập Đã Tồn Tại";
         }
         else
         {
             KhachHangDTO save = new KhachHangDTO()
             {
                 TaiKhoan = nguoiDung.TaiKhoan,
                 MatKhau  = nguoiDung.MatKhau,
                 VaiTro   = KhachHangDTO.VaiTroo.NguoiDungThuong
             };
             khachHangService.Create(save);
             ViewBag.TC = "Đăng Ký Thành Công";
             return(RedirectToAction("Login"));
         }
     }
     return(View(nguoiDung));
 }
Ejemplo n.º 3
0
        public HttpResponseMessage Create(HttpRequestMessage request, KhachHangViewModel khachhangViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    KhachHang khachhang = new KhachHang();
                    khachhang.UpdateKhachHang(khachhangViewModel);
                    var created = _khachHangService.Create(khachhang);
                    var mapper = Mapper.Map <KhachHang, KhachHangViewModel>(created);
                    _khachHangService.SaveChange();

                    response = request.CreateResponse(HttpStatusCode.Created, mapper);
                }
                return response;
            }));
        }
Ejemplo n.º 4
0
        public HttpResponseMessage CreateMutile(HttpRequestMessage request, ChiTietSuaChuaViewModel chitietSuaChuaViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;


                MayTinh maytinh = new MayTinh()
                {
                    Name = chitietSuaChuaViewModel.MayTinh.Name,
                    CategoryPC = chitietSuaChuaViewModel.MayTinh.CategoryPC,
                    Desciption = chitietSuaChuaViewModel.MayTinh.Desciption,
                    Status = chitietSuaChuaViewModel.MayTinh.Status,
                };
                var createdMayTinh = _maytinhService.Create(maytinh);
                _maytinhService.SaveChange();

                KhachHang khachhang = new KhachHang()
                {
                    Name = chitietSuaChuaViewModel.KhachHang.Name,
                    Address = chitietSuaChuaViewModel.KhachHang.Address,
                    PhoneNumber = chitietSuaChuaViewModel.KhachHang.PhoneNumber
                };
                var createdKhachHang = _khachhangService.Create(khachhang);
                _khachhangService.SaveChange();

                ChiTietSuaChua chitietsuachua = new ChiTietSuaChua();
                chitietSuaChuaViewModel.IDMayTinh = createdMayTinh.ID;
                chitietSuaChuaViewModel.IDKhachHang = createdKhachHang.ID;
                chitietsuachua.UpdateChiTietSuaChua(chitietSuaChuaViewModel);

                var created = _chitietSuaChuaService.Create(chitietsuachua);
                var mapper = Mapper.Map <ChiTietSuaChua, ChiTietSuaChuaViewModel>(created);
                _chitietSuaChuaService.SaveChange();

                response = request.CreateResponse(HttpStatusCode.Created, mapper);
                return response;
            }));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create(KHCreateRequest request)
        {
            var result = await _khachHangService.Create(request);

            return(Ok(result));
        }