public Vocabulary AddVocabulary(AddVocabularyViewModel vocabularyViewModel) { var vocabulary = new Vocabulary { Name = vocabularyViewModel.Name, SpeechPartId = vocabularyViewModel.SpeechPartId, TopicId = vocabularyViewModel.TopicId, Synonym = vocabularyViewModel.Synonym, Antonym = vocabularyViewModel.Antonym, MarathiMeaning = vocabularyViewModel.MarathiMeaning, ReadCount = 0, Meaning = vocabularyViewModel.Meaning, Sentences = (from sentence in vocabularyViewModel.Sentences where !string.IsNullOrWhiteSpace(sentence.SentenceExample) select new Sentence() { SentenceExample = sentence.SentenceExample, CreatedBy = _createdBy, CreatedOn = DateTime.Now, UpdatedBy = _createdBy, UpdatedOn = DateTime.Now }).ToList(), CreatedBy = _createdBy, CreatedOn = DateTime.Now, UpdatedBy = _createdBy, UpdatedOn = DateTime.Now }; _vocabContext.Vocabulary.Add(vocabulary); _vocabContext.SaveChanges(); return(vocabulary); }
public async Task <IActionResult> SaveVocabulary(AddVocabularyViewModel vocabularyViewModel) { var vocabulary = await _httpRestClientWrapper.ExecutePostAsync("http://localhost:61462/api/vocabulary", vocabularyViewModel); /*var restRequest = new HttpRequest * { * //Url = string.Format(_transactionServicesSettings.Value.EndPoint + StringFormat.GetMonNumber, transactionId), * Url = "http://localhost:61462/api/vocabulary/add/pageload", * HttpMethod = HttpMethod.Get * }; * var response = await _httpRestClientWrapper.ExecuteGetAsync(restRequest); * var addVocabularyViewModel = JsonConvert.DeserializeObject<AddVocabularyViewModel>(response); * * return View("AddVocabulary", addVocabularyViewModel);*/ var restRequest = new Common.Models.HttpRequest { Url = "http://localhost:61462/api/vocabulary", HttpMethod = HttpMethod.Get }; var response = await _httpRestClientWrapper.ExecuteGetAsync(restRequest); var vocabulariesViewModel = JsonConvert.DeserializeObject <VocabulariesViewModel>(response); return(View("Index", vocabulariesViewModel)); }
public AddVocabularyPage() { _viewModel = new AddVocabularyViewModel(); _viewModel.VocabularyItem = new VocabularyItem(); _viewModel.VocabularyItem.Date = _viewModel.Date = DateTime.Now; _viewModel.VocabularyItem.AccessLevel = 0; InitializeComponent(); BindingContext = _viewModel; ProgenyCollectionView.ItemsSource = _viewModel.ProgenyCollection; }
private List <AddVocabularyViewModel> GetVocabularyRows(IFormFile file) { var vocabularyRows = new List <AddVocabularyViewModel>(); const string folderName = "Upload"; var newPath = Path.Combine(_hostingEnvironment.WebRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } var sFileExtension = Path.GetExtension(file.FileName).ToLower(); var fileName = "VocabularyTemplate_" + DateTime.Now.ToFileTime() + sFileExtension; var fullPath = Path.Combine(newPath, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); stream.Position = 0; ISheet sheet; if (sFileExtension == ".xls") { var hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } else { var hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } var headerRow = sheet.GetRow(0); //Get Header Row int cellCount = headerRow.LastCellNum; for (var i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File { var row = sheet.GetRow(i); if (row == null) { continue; } if (row.Cells.All(d => d.CellType == CellType.Blank)) { continue; } var sentences = new List <SentenceViewModel>(); if (!string.IsNullOrWhiteSpace(row.GetCell(6).ToString())) { sentences.Add(new SentenceViewModel { SentenceExample = row.GetCell(6).ToString(), }); } if (!string.IsNullOrWhiteSpace(row.GetCell(7).ToString())) { sentences.Add(new SentenceViewModel { SentenceExample = row.GetCell(7).ToString(), }); } if (!string.IsNullOrWhiteSpace(row.GetCell(8).ToString())) { sentences.Add(new SentenceViewModel { SentenceExample = row.GetCell(8).ToString(), }); } var vocabularyRowDto = new AddVocabularyViewModel { Name = row.GetCell(0).ToString(), Meaning = row.GetCell(1).ToString(), MarathiMeaning = row.GetCell(2).ToString(), Synonym = row.GetCell(3).ToString(), Antonym = row.GetCell(4).ToString(), Sentences = sentences, SpeechPartId = 1, TopicId = 1 }; vocabularyRows.Add(vocabularyRowDto); } } return(vocabularyRows); }
public IActionResult Post([FromBody] AddVocabularyViewModel vocabularyViewModel) { var vocabulary = _vocabularyManager.AddVocabulary(vocabularyViewModel); return(Ok(vocabulary)); }
public Vocabulary AddVocabulary(AddVocabularyViewModel vocabularyViewModel) { return(_dataProvider.AddVocabulary(vocabularyViewModel)); }