Example #1
0
        // GET: Edit
        public ActionResult Edit(int?languageId, int?id)
        {
            if (languageId is null || id is null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var service = CreateWordService((int)languageId);
            var word    = service.GetWordById((int)id);

            if (word is null)
            {
                return(HttpNotFound());
            }

            var model =
                new WordEdit
            {
                WordId       = (int)id,
                WordName     = word.WordName,
                Translation  = word.Translation,
                PartOfSpeech = word.PartOfSpeech
            };

            return(View(model));
        }
Example #2
0
        // Update
        public bool UpdateWord(WordEdit model)
        {
            var entity =
                _context
                .Words
                .Single(e => e.WordId == model.WordId && e.UserId == _userId);

            entity.WordName     = model.WordName;
            entity.Translation  = model.Translation;
            entity.PartOfSpeech = model.PartOfSpeech;

            return(_context.SaveChanges() == 1);
        }
Example #3
0
        public ActionResult Edit([Deserialize] WordEditVars mdl, int?WId, string edited)
        {
            var word = unitOfWork.WordRepository.GetByID(mdl.mainWId);

            if (word.Descs.Any(d => d.dicId == mdl.DId))
            {
                if (WId == null)
                {
                    if (unitOfWork.WordRepository.Get(d => d.word == edited).Count() > 0)
                    {
                        throw new JsonCustomException(ControllerError.ajaxErrorWordDuplicate);
                    }
                }
                var current = unitOfWork.WordEditRepository.Get(d =>
                                                                d.editorId == WebSecurity.CurrentUserId &&
                                                                d.dicId == mdl.DId &&
                                                                d.wordId == mdl.mainWId).SingleOrDefault();

                if (current != null)
                {
                    current.sugWordId = WId;
                    current.text      = edited;
                    unitOfWork.WordEditRepository.Update(current);
                }
                else
                {
                    WordEdit wordedit = new WordEdit();
                    wordedit.date      = DateTime.UtcNow;
                    wordedit.dicId     = mdl.DId;
                    wordedit.wordId    = mdl.mainWId;
                    wordedit.sugWordId = WId;
                    wordedit.text      = edited;

                    wordedit.editorId = WebSecurity.CurrentUserId;

                    unitOfWork.WordEditRepository.Insert(wordedit);
                }

                unitOfWork.Save();
                return(Json(new { Url = Url.Action("Edit", "Word", new { WId = word.wordId, DId = mdl.DId }) }));
            }
            throw new JsonCustomException(ControllerError.ajaxError);
        }
Example #4
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Enter filepath to docx document.");
            string path = Console.ReadLine();

            using (WordEdit wordEdit = WordEdit.OpenEdit(path, LoadMode.KeepAlive))
            {
                Result replaceTokensResult = wordEdit.ReplaceTokens(TokenReplacements);

                if (replaceTokensResult.IsFailure)
                {
                    Console.WriteLine(replaceTokensResult.Error);
                    Console.WriteLine("Press any key to close the program. No changes will be made.");
                    Console.ReadKey();
                    return;
                }

                Result setCheckboxResult = wordEdit.SetCheckboxes(CheckboxValues);
                if (setCheckboxResult.IsFailure)
                {
                    Console.WriteLine(setCheckboxResult.Error);
                    Console.WriteLine("Press any key to close the program. No changes will be made.");
                }

                string fileName        = Path.GetFileNameWithoutExtension(wordEdit.File.FullName);
                string newPath         = Path.Combine(wordEdit.File.Directory.FullName, $"{fileName}.pdf");
                Result saveAsPdfResult = wordEdit.ExportAsPdf(newPath);

                string outputMessage = saveAsPdfResult.IsSuccess
                    ? $"Pdf saved at: {newPath}"
                    : saveAsPdfResult.Error;

                Console.WriteLine(outputMessage);
            }

            Console.WriteLine("All done. Press any key to quit");
        }
Example #5
0
        public ActionResult Edit(int languageId, int id, WordEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.WordId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateWordService(languageId);

            if (service.UpdateWord(model))
            {
                TempData["SaveResult"] = "Word was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Word was not updated.");
            return(View(model));
        }