private void DOReturnNumberGenerator(DOReturnModel model, int index) { index = 0; int YearNow = DateTime.Now.Year; var YearNowString = DateTime.Now.ToString("yy"); DOReturnModel lastLocalData = DbSet.IgnoreQueryFilters().Where(w => w.DOReturnType.Equals(model.DOReturnType)).OrderByDescending(o => o.AutoIncreament).FirstOrDefault(); if (lastLocalData == null) { model.AutoIncreament = 1 + index; model.DOReturnNo = $"{YearNowString}{model.DOReturnType}{model.AutoIncreament.ToString().PadLeft(6, '0')}"; } else { if (YearNow > lastLocalData.CreatedUtc.Year) { model.AutoIncreament = 1 + index; model.DOReturnNo = $"{YearNowString}{model.DOReturnType}{model.AutoIncreament.ToString().PadLeft(6, '0')}"; } else { model.AutoIncreament = lastLocalData.AutoIncreament + (1 + index); model.DOReturnNo = $"{YearNowString}{model.DOReturnType}{model.AutoIncreament.ToString().PadLeft(6, '0')}"; } } }
public async Task <int> CreateAsync(DOReturnModel model) { int result = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { int index = 0; do { model.Code = CodeGenerator.Generate(); }while (DbSet.Any(d => d.Code.Equals(model.Code))); DOReturnNumberGenerator(model, index); doReturnLogic.Create(model); index++; result = await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(result); }
public async Task <int> UpdateAsync(int id, DOReturnModel model) { using (var transaction = DbContext.Database.BeginTransaction()) { try { doReturnLogic.UpdateAsync(id, model); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(await DbContext.SaveChangesAsync()); }
public async Task <int> DeleteAsync(int id) { using (var transaction = DbContext.Database.BeginTransaction()) { try { DOReturnModel model = await doReturnLogic.ReadByIdAsync(id); if (model != null) { DOReturnModel doReturnModel = new DOReturnModel(); doReturnModel = model; await doReturnLogic.DeleteAsync(id); } } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(await DbContext.SaveChangesAsync()); }
public async Task <int> UpdateAsync(int id, DOReturnModel model) { doReturnLogic.UpdateAsync(id, model); return(await DbContext.SaveChangesAsync()); }