public QRFCounterResponse GetNextReferenceNumber(QRFCounterRequest request) { var result = (from c in _MongoContext.mSysCounters.AsQueryable() where c.CounterType == request.CounterType select c.LastReferenceNumber).FirstOrDefault(); var response = new QRFCounterResponse(); if (result != 0) { long val = ++result; _MongoContext.mSysCounters.UpdateOne(x => x.CounterType == request.CounterType, Builders <mSysCounters> .Update.Set(x => x.LastReferenceNumber, val)); response.LastReferenceNumber = val; } else { var item = new mSysCounters { CounterType = request.CounterType, LastReferenceNumber = 1, CreateDate = DateTime.Now, EditDate = DateTime.Now, CreateUser = "******", EditUser = "******" }; _MongoContext.mSysCounters.InsertOne(item); response.LastReferenceNumber = item.LastReferenceNumber; } return(response); }
public QRFCounterResponse GetNextReferenceNumber([FromBody] QRFCounterRequest request) { if (!string.IsNullOrWhiteSpace(request.CounterType)) { var response = _genericRepository.GetNextReferenceNumber(request); if (response.LastReferenceNumber != 0) { response.Status = "Success"; } else { response.Status = "Invalid CounterType"; } return(response); } else { var response = new QRFCounterResponse(); response.Status = "Failure"; return(response); } }