예제 #1
0
        public async Task <IActionResult> Create(TeamIM team)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }
            try
            {
                var model = _mapper.Map <Team>(team);
                model.CreatedBy   = User.Identity.Name;
                model.CreatedDate = DateTime.Now;


                _context.Add(model);
                await _context.SaveChangesAsync();

                AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Team));
                return(Json(AR));
            }
            catch (Exception er)
            {
                AR.Setfailure(er.Message);
                return(Json(AR));
            }
        }
        public JsonResult Create(TeamIM team)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }

            try
            {
                var newTeam = _mapper.Map <TeamIM, Team>(team);

                var result = _teamServices.Create(newTeam);



                int count;
                int pageSize = SettingsManager.Team.PageSize;
                var list     = _teamServices.GetTeamdElements(0, pageSize, string.Empty, out count);

                AR.Data = RenderPartialViewToString("_TeamList", list);

                AR.SetSuccess(String.Format(Messages.AlertCreateSuccess, EntityNames.Team));
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
            catch (Exception er)
            {
                AR.Setfailure(er.Message);
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
        }
        public ActionResult Edit(TeamIM page)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }

            try
            {
                var old      = _teamServices.GetById(page.Id);
                var editTeam = _mapper.Map(page, old);



                _teamServices.Update(editTeam);



                // var pageVM = _mapper.Map<TeamVM>(editTeam);

                AR.Id   = page.Id;
                AR.Data = RenderPartialViewToString("_TeamItem", editTeam);

                AR.SetSuccess(String.Format(Messages.AlertUpdateSuccess, EntityNames.Team));
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
            catch (Exception er)
            {
                AR.Setfailure(er.Message);
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
        }
        // GET: Admin/Teams/Create
        public ActionResult Create()
        {
            TeamIM team = new TeamIM()
            {
                Active = true
            };

            return(PartialView("_Create", team));
        }
예제 #5
0
        public async Task <IActionResult> Edit(int id, TeamIM team)
        {
            if (id != team.Id)
            {
                AR.Setfailure(Messages.HttpNotFound);
                return(Json(AR));
            }

            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                //page.Body = Regex.Replace(page.Body, @"(?i)(?<=<img\b[^>]*?src=(['""]?))(?!http://)[^'""]+(?=\1)", "http://sbe.anyacos.com$0");

                //var ishas = await _context.Pages.CountAsync(d => d.SeoName == page.SeoName.ToLower() && d.Id != id);
                //if (ishas > 0)
                //{
                //    ModelState.AddModelError("SeoName", "已经存在此友好网址");
                //    AR.Setfailure(GetModelErrorMessage());
                //    return Json(AR);
                //}

                var model = await _context.Teams.SingleOrDefaultAsync(d => d.Id == id);

                model             = _mapper.Map(team, model);
                model.UpdatedBy   = User.Identity.Name;
                model.UpdatedDate = DateTime.Now;



                _context.Update(model);
                await _context.SaveChangesAsync();

                AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Team));
                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PageExists(team.Id))
                {
                    AR.Setfailure(Messages.HttpNotFound);
                    return(Json(AR));
                }
                else
                {
                    throw;
                }
            }
        }