コード例 #1
0
        public async Task<bool> Update(UnCmGps item)
        {
            var gps = await IdExist(item.Id);

            gps.Name = item.Name;
            if (!string.IsNullOrEmpty(item.MsgEn)) gps.MsgEn = item.MsgEn;
            if (!string.IsNullOrEmpty(item.MsgTh)) gps.MsgTh = item.MsgTh;

            _db.Entry(gps).State = EntityState.Modified;
            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException exception)
            {
                throw new DbUpdateConcurrencyException(exception.Message);
            }

            return true;
        }
コード例 #2
0
        public async Task<UnCmGps> Add(UnCmGps item)
        {
            var gps = new UnCmGps
            {
                Name = item.Name,
                Id = await UsedIdName(item.Id)
            };

            if (!string.IsNullOrEmpty(item.MsgEn)) gps.MsgEn = item.MsgEn;
            if (!string.IsNullOrEmpty(item.MsgTh)) gps.MsgTh = item.MsgTh;

            gps = _db.UnCmGpss.Add(gps);
            try
            {
                await _db.SaveChangesAsync();
                return gps;
            }
            catch (DbUpdateConcurrencyException exception)
            {
                throw new DbUpdateConcurrencyException(exception.Message);
            }
        }