Exemplo n.º 1
0
        public ActionResult Edit(LanguagesViewModels model)
        {
            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 languages", "Language is edited successfully.");

            model.DateChanged = DateTime.Now;
            model.UserName    = User.Identity.Name;
            languagesService.Update(Mapper.Map <Languages>(model));

            if (Request.IsAjaxRequest())
            {
                return(PartialView("Index", languagesService.GetByActiveProject(UserActiveProject).ProjectTo <LanguagesViewModels>()));
            }

            return(View("Index", languagesService.GetByActiveProject(UserActiveProject).ProjectTo <LanguagesViewModels>()));
        }
Exemplo n.º 2
0
        public ActionResult Create(LanguagesViewModels model)
        {
            if (!ModelState.IsValid)
            {
                Response.Headers["InvalidModel"] = "false";

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

                return(View(model));
            }
            if (User.Identity.GetActiveProject() == "0")
            {
                SetViewBagsAndHeaders(Request.IsAjaxRequest(), "Add new language", "You have to create project first.");
                ModelState.AddModelError("", "Create your first project and then you can add languages.");
                if (Request.IsAjaxRequest())
                {
                    return(PartialView(model));
                }

                return(View(model));
            }
            SetViewBagsAndHeaders(Request.IsAjaxRequest(), "All added languages", "New Language is created successfully.");
            model.IdProject   = int.Parse(User.Identity.GetActiveProject());
            model.DateChanged = DateTime.Now;
            model.DateCreated = DateTime.Now;
            model.UserName    = User.Identity.Name;
            languagesService.Add(Mapper.Map <Languages>(model));

            if (Request.IsAjaxRequest())
            {
                return(PartialView("Index", languagesService.GetByActiveProject(UserActiveProject).ProjectTo <LanguagesViewModels>()));
            }

            return(View("Index", languagesService.GetByActiveProject(UserActiveProject).ProjectTo <LanguagesViewModels>()));
        }