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

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

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

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

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

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