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)); }
public ActionResult Index() { var model = new IndexViewModels { Languages = { CurrentCount = langService.GetByActiveProject(UserActiveProject).Count(), ActiveCount = langService.GetActiveByActiveProject(UserActiveProject).Count() }, Contexts = { CurrentCount = phrsContService.GetAllByIdProject(UserActiveProject, User.Identity.GetUserId()).Count(), Translated = phrsContService.GetTranslatedByIdProject(UserActiveProject, User.Identity.GetUserId()).Count() }, Projects = { ProjectCount = projectServices.GetForUser(User.Identity.GetUserId()).Count() }, SystemStabilityBox = GetSystemStabilityLoggsViewModel(), BearerToken = tokenContainer.ApiToken?.ToString() }; SetViewBagsAndHeaders(Request.IsAjaxRequest(), "Dashboard", "Hello! This is your administration panel."); if (Request.IsAjaxRequest()) { return(PartialView(model)); } return(View(model)); }
// GET: Sections public async Task <ActionResult> FirstRow(string id) { if (id == "Home" || id == "") { var model = new HomeFirstRowSectionViewModel(); //model.BearerToken = tokenContainer?.ApiToken.ToString(); return(PartialView("HomeFirstRowSection", model)); } if (id == "Resources") { var model = new ResourcesFirstRowSectionViewModel(); model.Languages.CurrentCount = langService.GetByActiveProject(UserActiveProject).Count(); model.Languages.ActiveCount = langService.GetActiveByActiveProject(UserActiveProject).Count(); model.Contexts.CurrentCount = phrsContService.GetAllByIdProject(UserActiveProject, User.Identity.GetUserId()).Count(); model.Contexts.Translated = phrsContService.GetTranslatedByIdProject(UserActiveProject, User.Identity.GetUserId()).Count(); model.Projects.ProjectCount = projectServices.GetForUser(User.Identity.GetUserId()).Count(); return(PartialView("ResourcesFirstRowSection", model)); } if (id == "Contexts") { var model = new ContextsFirstRowSectionViewModel(); model.Languages.CurrentCount = langService.GetByActiveProject(UserActiveProject).Count(); model.Languages.ActiveCount = langService.GetActiveByActiveProject(UserActiveProject).Count(); model.Projects.ProjectCount = projectServices.GetForUser(User.Identity.GetUserId()).Count(); return(PartialView("ContextsFirstRowSection", model)); } if (id == "Languages") { var model = new CurrentProjectInfoBoxViewModel(); model.ProjectCount = projectServices.GetForUser(User.Identity.GetUserId()).Count(); return(PartialView("InnerPartials/CurrentProjectInfoBox", model)); } return(PartialView("Default")); }
public ActionResult GettingStarted() { ViewBag.IdLanguage = new SelectList( languagesService.GetActiveByActiveProject(UserActiveProject), "IdLanguage", "Name"); ViewBag.IdPhraseContext = new SelectList( contextServices.GetAllByIdProject(UserActiveProject, User.Identity.GetUserId()), "IdPhraseContext", "Context"); SetViewBagsAndHeaders(Request.IsAjaxRequest(), prefix, "Multi-Language - Getting Started"); if (Request.IsAjaxRequest()) { return(PartialView()); } return(View()); }
public IQueryable <PhrasesContext> GetTranslatedByIdProject(int IdProject, string UserId) { var activeLang = langService.GetActiveByActiveProject(IdProject).Count(); return(phrasesContext.All().Where(pc => pc.IdProject == IdProject && pc.UserId == UserId && pc.Phrases.Count() == activeLang)); }