public async Task<bool> Update(UnCmComm item) { var comm = await IdExist(item.Id); comm.Name = item.Name; if (!string.IsNullOrEmpty(item.MsgEn)) comm.MsgEn = item.MsgEn; if (!string.IsNullOrEmpty(item.MsgTh)) comm.MsgTh = item.MsgTh; _db.Entry(comm).State = EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException exception) { throw new DbUpdateConcurrencyException(exception.Message); } return true; }
public async Task<UnCmComm> Add(UnCmComm item) { var comm = new UnCmComm { Name = item.Name, Id = await UsedIdName(item.Id) }; if (!string.IsNullOrEmpty(item.MsgEn)) comm.MsgEn = item.MsgEn; if (!string.IsNullOrEmpty(item.MsgTh)) comm.MsgTh = item.MsgTh; comm = _db.UnCmComms.Add(comm); try { await _db.SaveChangesAsync(); return comm; } catch (DbUpdateConcurrencyException exception) { throw new DbUpdateConcurrencyException(exception.Message); } }