예제 #1
0
        public ActionResult Edit([Bind(Include = "IdPhrase,IdPhraseContext,IdLanguage,PhraseText,DateCreated")] ResourcesViewModels model)
        {
            SetViewBags();

            if (!ModelState.IsValid)
            {
                SetViewBagsAndHeaders(Request.IsAjaxRequest(), "Edit", "You have some validation errors.");
                if (Request.IsAjaxRequest())
                {
                    return(PartialView(model));
                }

                return(View(model));
            }
            SetViewBagsAndHeaders(Request.IsAjaxRequest(), "All added resources", "Resource is edited successfully.");

            model.DateChanged = DateTime.Now;
            model.UserId      = User.Identity.GetUserId();

            phrasesService.Update(Mapper.Map <Phrases>(model));

            if (Request.IsAjaxRequest())
            {
                return(PartialView("Index", phrasesService.GetAll().ProjectTo <ResourcesViewModels>()));
            }

            return(View("Index", phrasesService.GetAll().ProjectTo <ResourcesViewModels>()));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "IdPhrase,IdPhraseContext,IdLanguage,PhraseText")] ResourcesViewModels model)
        {
            ViewBag.IdLanguage      = new SelectList(languagesService.GetActiveByActiveProject(UserActiveProject), "IdLanguage", "Name", model.IdLanguage);
            ViewBag.IdPhraseContext = new SelectList(contextServices.GetAllByIdProject(UserActiveProject, User.Identity.GetUserId()), "IdPhraseContext", "Context", model.IdPhraseContext);

            if (!ModelState.IsValid)
            {
                Response.Headers["InvalidModel"] = "false";

                SetViewBagsAndHeaders(Request.IsAjaxRequest(), "Add new resource", "You have some validation errors.");
                if (Request.IsAjaxRequest())
                {
                    return(PartialView(model));
                }

                return(View(model));
            }
            var currentPhrases = phrasesService.GetAllByIdProject(UserActiveProject, User.Identity.GetUserId()).Where(p => p.IdPhraseContext == model.IdPhraseContext && p.IdLanguage == model.IdLanguage);

            if (currentPhrases.Any())
            {
                SetViewBagsWIthActiveValue(model.IdLanguage, model.IdPhraseContext);

                ModelState.AddModelError("", "Translation for this context in this language is already defined.");

                SetViewBagsAndHeaders(Request.IsAjaxRequest(), "Add new resource", $@"Translation for this context in this language is already defined.
Please choose different language or edit current translation <a href='{Url.Action("Edit", new { id = currentPhrases.First().IdPhrase })}' >here!</a>");
                if (Request.IsAjaxRequest())
                {
                    return(PartialView(model));
                }

                return(View(model));
            }
            SetViewBagsAndHeaders(Request.IsAjaxRequest(), "Add new resource", "New resource is created successfully.");

            model.DateChanged = DateTime.Now;
            model.DateCreated = DateTime.Now;
            model.UserId      = User.Identity.GetUserId();

            phrasesService.Add(Mapper.Map <Phrases>(model));
            model.PhraseText = "";
            if (Request.IsAjaxRequest())
            {
                return(PartialView(model));
            }

            return(View(model));
        }