コード例 #1
0
        public async Task CreateLinkAsync(LinkIM item)
        {
            var link = _mapper.Map <Link>(item);

            link.CreatedDate = DateTime.Now;
            link.CreatedBy   = await _sessionStorageService.GetItemAsync <string>("username");

            await _db.AddAsync(link);

            await _db.SaveChangesAsync();
        }
コード例 #2
0
        public async Task UpdateLinkAsync(int id, LinkIM item)
        {
            var origin = await _db.Links.FindAsync(id);

            var link = _mapper.Map(item, origin);

            link.UpdatedDate = DateTime.Now;
            link.UpdatedBy   = await _sessionStorageService.GetItemAsync <string>("username");

            _db.Update(link);
            await _db.SaveChangesAsync();
        }
コード例 #3
0
        public ActionResult Add()
        {
            var link = new LinkIM
            {
                Active = true
            };

            var categorys  = _categoryServices.GetAll().OrderByDescending(m => m.Importance).ToList();
            var lCategorys = new SelectList(categorys, "Id", "Title");

            ViewBag.Categories = lCategorys;
            return(View(link));
        }
コード例 #4
0
ファイル: LinksController.cs プロジェクト: doubletong/QNZOA
        public async Task <IActionResult> PostLink([FromBody] LinkIM link)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var model = _mapper.Map <Link>(link);

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


            return(Ok());
        }
コード例 #5
0
        public JsonResult Add(LinkIM vm)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }

            try
            {
                var newLink = _mapper.Map <LinkIM, Link>(vm);
                var result  = _linkServices.Create(newLink);

                AR.SetSuccess(String.Format(Messages.AlertCreateSuccess, EntityNames.Link));
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
            catch (Exception er)
            {
                AR.Setfailure(er.Message);
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
        }
コード例 #6
0
        public JsonResult Edit(LinkIM vm)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }

            try
            {
                var old      = _linkServices.GetById(vm.Id);
                var editLink = _mapper.Map(vm, old);

                _linkServices.Update(editLink);

                AR.SetSuccess(String.Format(Messages.AlertUpdateSuccess, EntityNames.Link));
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
            catch (Exception er)
            {
                AR.Setfailure(er.Message);
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }
        }
コード例 #7
0
ファイル: LinksController.cs プロジェクト: doubletong/QNZOA
        public async Task <IActionResult> PutLink([FromRoute] int id, [FromBody] LinkIM link)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != link.Id)
            {
                return(BadRequest());
            }

            var model = await _context.Links.FirstOrDefaultAsync(d => d.Id == id);

            model = _mapper.Map(link, model);

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

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

            return(Ok());
        }