コード例 #1
0
        public async Task <IActionResult> UpdatePhoneBook([FromBody] PhoneBookViewModel PhoneBook)
        {
            _ = new ObjectResult(false);

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                else
                {
                    var newPhoneBook = PhoneBook.ReverseMap();

                    await _PhoneBookApi.UpdatePhoneBook(newPhoneBook);

                    var PhoneBookvm = new PhoneBookViewModel(newPhoneBook);

                    return(Ok(new { message = "PhoneNumber is updated successfully." }));
                }
            }
            catch (Exception ex)
            {
                _loggingApi.Add(new SYS_Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, CreatedDate = DateTime.Now
                });
                await _loggingApi.Commit();

                return(NotFound(new { message = "An error occured" }));
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetPhoneBooks()
        {
            _ = new ObjectResult(false);

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var PhoneBooks = await _PhoneBookApi.GetAllPhoneBooks();

                if (PhoneBooks == null)
                {
                    return(NotFound(new { message = "Phone Books not found" }));
                }
                else
                {
                    var item = PhoneBookViewModel.MultiplePhoneBooksMap(PhoneBooks);

                    return(new ObjectResult(item));
                }
            }
            catch (Exception ex)
            {
                _loggingApi.Add(new SYS_Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, CreatedDate = DateTime.Now
                });
                await _loggingApi.Commit();

                return(NotFound(new { message = "An error occured" }));
            }
        }
コード例 #3
0
        public async Task <IActionResult> GetPhoneBookByID(int Id)
        {
            _ = new ObjectResult(false);

            try
            {
                var PhoneBook = await _PhoneBookApi.GetPhoneBookByID(Id);

                if (PhoneBook == null)
                {
                    return(NotFound(new { message = "Phone Books not found" }));
                }
                else
                {
                    PhoneBookViewModel item = new PhoneBookViewModel();

                    item.MapSinglePhoneBook(PhoneBook);

                    return(new ObjectResult(item));
                }
            }
            catch (Exception ex)
            {
                _loggingApi.Add(new SYS_Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, CreatedDate = DateTime.Now
                });
                await _loggingApi.Commit();

                return(NotFound(new { message = "An error occured" }));
            }
        }
コード例 #4
0
        public IHttpActionResult Put(PhoneBookViewModel phoneBookViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            PhoneBookViewModel existingPhoneBook = null;

            using (var phoneBookEntities = new CIB_PhoneBookEntities())
            {
                existingPhoneBook = phoneBookEntities.PhoneBooks.Where(pb => pb.phonebookid == phoneBookViewModel.phonebookid) as PhoneBookViewModel;

                if (existingPhoneBook != null)
                {
                    existingPhoneBook.name         = phoneBookViewModel.name;
                    existingPhoneBook.datemodified = DateTime.Now;

                    phoneBookEntities.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
コード例 #5
0
        public ActionResult SearchPhoneBook(PhoneBookViewModel viewModel)
        {
            string sqlWhereString;
            string sqlAndString;

            if (viewModel.ColValue == "" || viewModel.ColValue.Length == 0)
            {
                sqlWhereString = " 1= 1";
            }
            else
            {
                sqlWhereString = "zza04 LIKE '%" + viewModel.ColValue + "%' ";
            }
            if (viewModel.Zza06 == "" || viewModel.Zza06 == null)
            {
                sqlAndString = "";
            }
            else
            {
                sqlAndString = " zza06 = '" + viewModel.Zza06 + "' ";
            }



            PhoneBookSQLConnector phoneBookSQLConnector = new PhoneBookSQLConnector();

            PhoneBookViewModel phoneBookViewModel = new PhoneBookViewModel();

            phoneBookViewModel.UserBasicDataList = phoneBookSQLConnector.GetUserBasicDataByCriteria(sqlWhereString, sqlAndString);
            phoneBookViewModel.SelectListItems   = phoneBookSQLConnector.getOfficeItem();

            TempData["phoneBookViewModel"] = phoneBookViewModel;

            return(Redirect("BackToPhoneBookSearch"));
        }
コード例 #6
0
        public async Task <int> Update(PhoneBookViewModel entry)
        {
            var entity = _mapper.Map <DomainModels.PhoneBook>(entry);
            await _unitofwork.Books.Put(entity);

            return(await _unitofwork.CompleteAsync());
        }
コード例 #7
0
        // GET: Phonebook
        public ActionResult PhoneBookSearch()
        {
            PhoneBookSQLConnector phoneBookSQLConnector = new PhoneBookSQLConnector();
            PhoneBookViewModel    phoneBookViewModel    = new PhoneBookViewModel();

            phoneBookViewModel.SelectListItems = phoneBookSQLConnector.getOfficeItem();

            return(View(phoneBookViewModel));
        }
コード例 #8
0
        public async Task <IActionResult> Create(PhoneBookViewModel viewModel)
        {
            var result = await HttpClientPut($"phonebook/save", JsonConvert.SerializeObject(viewModel));

            if (result == null)
            {
                return(View());
            }
            return(RedirectToAction(nameof(Index)));
        }
コード例 #9
0
        public async Task GetPhoneBookByIdMustSuccess(GetPhoneBook query, PhoneBookViewModel expected)
        {
            _dispatcher.QueryAsync(query).Returns(Task.FromResult(expected));

            var result = await _controller.Get(query);

            var okResult = Assert.IsType <OkObjectResult>(result);

            Assert.NotNull(okResult.Value);
            Assert.Equal(expected, okResult.Value);
        }
コード例 #10
0
        public ActionResult BackToPhoneBookSearch()
        {
            PhoneBookViewModel phoneBookViewModel = (PhoneBookViewModel)TempData["phoneBookViewModel"];

            if (TempData["LastPostFormData"] == null)
            {
                return(RedirectToAction("PhoneBookSearch"));
            }
            var objModel = (Models.PhoneBookViewModel)TempData["LastPostFormData"];

            return(View("PhoneBookSearch", phoneBookViewModel));
        }
コード例 #11
0
 public ActionResult Edit(PhoneBookViewModel phonebook)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri("http://localhost:44302/api/ApiPhonebook");
         //HTTP POST
         var putTask = client.PutAsJsonAsync <PhoneBookViewModel>("ApiPhonebook", phonebook);
         putTask.Wait();
         var result = putTask.Result;
         if (result.IsSuccessStatusCode)
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(phonebook));
 }
コード例 #12
0
        public JsonResult PhoneBookJson(PhoneBookViewModel model)
        {
            List <PhoneBookViewModel> list;
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var query = db.Person.Where(x => x.Active == true);

                    if (model.id != null)
                    {
                        query = query.Where(x => x.BranchId == model.id);
                    }

                    list = query.Select(x => new PhoneBookViewModel()
                    {
                        id          = x.BranchId,
                        branchName  = x.Branch.Name,
                        branchPhone = x.Branch.Phone,
                        firstName   = x.FirstName,
                        lastName    = x.LastName,
                        personPhone = x.MobileNumber
                    }).ToList();

                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list = list
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
コード例 #13
0
        // GET: PhoneBook/Edit/5
        public ActionResult Edit(int id)
        {
            PhoneBookViewModel phonebook = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:44302/api/");
                //HTTP GET
                var responseTask = client.GetAsync("ApiPhonebook?id=" + id.ToString());
                responseTask.Wait();
                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <PhoneBookViewModel>();
                    readTask.Wait();
                    phonebook = readTask.Result;
                }
            }
            return(View(phonebook));
        }
コード例 #14
0
        public ActionResult HR(PhoneBookViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("PhoneBook/PhoneBookSearch"));
            }

            TempData["LastPostFormData"] = viewModel;
            string sqlWhereString;
            string sqlAndString;

            if (viewModel.ColValue == "" || viewModel.ColValue == null)
            {
                sqlWhereString = " zza06 LIKE '%" + viewModel.Zza06 + "910100' ";
            }
            else
            {
                sqlWhereString = "zza04 LIKE '%" + viewModel.ColValue + "%' ";
            }
            if (viewModel.Zza06 == "" || viewModel.Zza06 == null)
            {
                sqlAndString = "";
            }
            else
            {
                sqlAndString = " zza06 = '" + viewModel.Zza06 + "' ";
            }



            PhoneBookSQLConnector phoneBookSQLConnector = new PhoneBookSQLConnector();

            PhoneBookViewModel phoneBookViewModel = new PhoneBookViewModel();

            phoneBookViewModel.UserBasicDataList = phoneBookSQLConnector.GetUserBasicDataByCriteria(sqlWhereString, sqlAndString);
            phoneBookViewModel.SelectListItems   = phoneBookSQLConnector.getOfficeItem();

            TempData["phoneBookViewModel"] = phoneBookViewModel;

            return(Redirect("BackToPhoneBookSearch"));
        }
コード例 #15
0
        public IHttpActionResult PostNewPhoneBook(PhoneBookViewModel phoneBook)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            using (var pb = new CIB_PhoneBookEntities())
            {
                pb.PhoneBooks.Add(new PhoneBook()
                {
                    name         = phoneBook.name,
                    datecreated  = DateTime.Now,
                    datemodified = DateTime.Now,
                    active       = phoneBook.active
                });

                pb.SaveChanges();
            }

            return(Ok());
        }
コード例 #16
0
        // PUT: api/ApiPhoneBook/5
        public IHttpActionResult Put(PhoneBookViewModel phonebook)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid data"));
            }
            using (var ctx = new ABSAEntities())
            {
                var existingphonenumber = ctx.PhoneBooks.Where(s => s.Name == phonebook.Name).FirstOrDefault <PhoneBook>();

                if (existingphonenumber == null)
                {
                    existingphonenumber.Name        = phonebook.Name;
                    existingphonenumber.PhoneNumber = phonebook.PhoneNumber;

                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }
            return(Ok());
        }
コード例 #17
0
        public ActionResult SearchPhoneBookButton(string Zza06)
        {
            string sqlAndString;

            if (Zza06 == "" || Zza06 == null)
            {
                sqlAndString = "";
            }
            else
            {
                sqlAndString = " zza06 = '" + Zza06 + "' ";
            }

            PhoneBookSQLConnector phoneBookSQLConnector = new PhoneBookSQLConnector();

            PhoneBookViewModel phoneBookViewModel = new PhoneBookViewModel();

            phoneBookViewModel.UserBasicDataList = phoneBookSQLConnector.GetUserBasicDataByCriteria(" 1=1 ", sqlAndString);
            phoneBookViewModel.SelectListItems   = phoneBookSQLConnector.getOfficeItem();

            TempData["phoneBookViewModel"] = phoneBookViewModel;

            return(Redirect("BackToPhoneBookSearch"));
        }
コード例 #18
0
        public MainWindow()
        {
            InitializeComponent();

            DataContext = new PhoneBookViewModel(new DialogSerivice(), new JsonFileService(), new XMLFileService());
        }
コード例 #19
0
        public ActionResult BackToPhoneBookSearch()
        {
            PhoneBookViewModel phoneBookViewModel = (PhoneBookViewModel)TempData["phoneBookViewModel"];

            return(View("PhoneBookSearch", phoneBookViewModel));
        }
コード例 #20
0
        public async Task <IActionResult> Put([FromBody] PhoneBookViewModel phoneBookModel)
        {
            var result = await _service.Update(phoneBookModel);

            return(Ok(result));
        }