public async Task <IActionResult> PutPersonMasterLabel([FromRoute] int id, [FromBody] PersonMasterLabel personMasterLabel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != personMasterLabel.PersonID)
            {
                return(BadRequest());
            }

            _context.Entry(personMasterLabel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonMasterLabelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostPersonMasterLabel([FromBody] PersonMasterLabel personMasterLabel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.PersonMasterLabel.Add(personMasterLabel);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (PersonMasterLabelExists(personMasterLabel.PersonID))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetPersonMasterLabel", new { id = personMasterLabel.PersonID }, personMasterLabel));
        }
        public async Task <IActionResult> Create([Bind("PersonID,LabelID")] PersonMasterLabel personMasterLabel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(personMasterLabel);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["LabelID"]  = new SelectList(_context.Lable, "Id", "Name", personMasterLabel.LabelID);
            ViewData["PersonID"] = new SelectList(_context.Person, "Id", "Name", personMasterLabel.PersonID);
            return(View(personMasterLabel));
        }
Esempio n. 4
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Details([FromBody] PersonMasterLabel personMasterLabel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.PersonMasterLabel.Add(personMasterLabel);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (PersonMasterLabelExists(personMasterLabel.PersonID))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }

            //查询标签的使用以及次数
            var label = from pm in _context.PersonMasterLabel
                        join pu in _context.PersonUseLabel on pm.PersonID equals pu.PersonID
                        join c in _context.Lable on pm.LabelID equals c.Id
                        group pu by new { wna = pu.PersonID, sa = pm.LabelID, cname = c.Name } into g
                select new
            {
                cname    = g.Key.cname,
                PersonID = g.Key.wna,
                LabelID  = g.Key.sa
            };

            List <Label> labelList = new List <Label>();

            foreach (var item in label)
            {
                Label l = new Label();
                l.Id   = item.LabelID;
                l.Name = item.cname;
                labelList.Add(l);
            }

            ViewData["LabelList"] = labelList;
            ViewData["Personid"]  = personMasterLabel.PersonID;
            return(PartialView("_PartialPage", ViewData["Personid"]));
        }