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