public virtual async Task <IHttpActionResult> AutoCompleteList(Y?id = default(Y?), string text = default(string)) { var result = await service.AutoCompleteList(id, text); if (result == null) { return(Content(HttpStatusCode.OK, new string[0])); } return(Ok(result)); }
public virtual async Task <G> GetByID(Y id, Y?userID = default(Y?), bool isDeleted = false) { var query = uow.Repository <D>().Query(isDeleted).Where(Predicate.Equal <D, Y>("ID", id)); //İlgili kaydın, ilgili kullanıcıya ait olma durumunu kontrol etmektedir. if (userID != null) { query = query.Where(Predicate.Equal <D, Y>("CreateBy", userID.Value)); } return(await query.ProjectTo <G>().FirstOrDefaultAsync()); }
public virtual async Task <C> GetById(Y id, Y?userId = default(Y?), bool isDeleted = false) { var query = _uow.Repository <D>().Query(isDeleted) .Equal("Id", id); //İlgili kaydın, ilgili kullanıcıya ait olma durumunu kontrol etmektedir. if (userId != null) { query = query.Equal("CreateBy", userId.Value); } return(await query.ProjectTo <C>().FirstOrDefaultAsync()); }
/// <summary> /// New Recoard /// </summary> /// <param name="model"></param> /// <param name="userID"></param> /// <param name="isCommit"></param> /// <returns></returns> public virtual async Task <APIResult <Guid> > Add(A model, Y?userID, bool isCommit = true) { try { D entity = AddMapping(model); Y pkType = default(Y); if (pkType is Guid) { if ((entity.ID as Guid?).IsNullOrEmpty()) { entity.ID = Guid.NewGuid(); } } if (entity is ITableEntity <Y> || entity is UserTableEntity <Y> ) { if (userID != null && entity is ITableEntity <Y> ) { (entity as ITableEntity <Y>).CreateByID = Guid.Parse(userID.ToString()); } if (entity is ITableEntity <Y> ) { (entity as ITableEntity <Y>).CreateDT = DateTime.Now; } if (entity is UserTableEntity <Y> ) { (entity as UserTableEntity <Y>).CreateDT = DateTime.Now; } } _uow.Repository <D>().Add(entity); if (isCommit) { await _uow.SaveChangesAsync(); } return(new APIResult <Guid> { Data = entity.ID, IsSuccess = true }); } catch (Exception ex) { return(new APIResult <Guid>() { Message = ex.ToString() }); } }
public virtual async Task <APIResult <Guid> > Delete(Y id, Y?userID = null, bool isCommit = true, bool checkAuthorize = false) { try { Guid modelID = Guid.Parse(id.ToString()); D entity = await _uow.Repository <D>().QueryGetBy(x => x.ID == modelID); if (entity == null) { return(new APIResult <Guid>() { Data = modelID, Message = Messages.NoRecord }); } if (entity is ITableEntity <Y> ) { //Access Control if (userID != null && checkAuthorize) { if (!(entity as ITableEntity <Y>).CreateByID.Equals(userID.Value)) { return(new APIResult <Guid>() { Message = Messages.Unauthorized }); } } (entity as ITableEntity <Y>).UpdateDT = DateTime.Now; (entity as ITableEntity <Y>).UpdateByID = Guid.Parse(userID.Value.ToString()); } entity.IsDeleted = true; if (isCommit) { await _uow.SaveChangesAsync(); } return(new APIResult <Guid>() { Data = modelID, IsSuccess = true }); } catch (Exception ex) { return(new APIResult <Guid>() { Message = ex.ToString() }); } }
public static void BiThreshold <T, Y>(T left, Y right, Thresholds <T> leftThresholds, Thresholds <Y> rightThresholds, Action <Severity, T?, Y?> action, IComparer <T>?leftComparer = null, IComparer <Y>?rightComparer = null, Func <Severity?, Severity?, Severity?>?merge = null) where T : struct where Y : struct { if (merge == null) { merge = (s1, s2) => { if (s1 == null) { return(s2); } if (s2 == null) { return(s1); } return((Severity)Math.Max((int)s1, (int)s2)); }; } Severity?leftSeverity = null; T? leftThreshold = null; Threshold(left, leftThresholds, (severity, threshold) => { leftSeverity = severity; leftThreshold = threshold; }, leftComparer); Severity?rightSeverity = null; Y? rightThreshold = null; Threshold(right, rightThresholds, (severity, threshold) => { rightSeverity = severity; rightThreshold = threshold; }, rightComparer); var finalSeverity = merge(leftSeverity, rightSeverity); if (finalSeverity != null) { action(finalSeverity.Value, leftThreshold, rightThreshold); } }
public virtual async Task <IHttpActionResult> AutoCompleteList([FromUri] P parameters, Y?id = default(Y?), string text = default(string)) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _service.AutoCompleteList(parameters, id, text); if (result == null) { return(Content(HttpStatusCode.OK, new string[0])); } return(Ok(result)); }
public virtual async Task <APIResult> Update(U model, Y?userID = default(Y?), bool isCommit = true, bool checkAuthorize = false) { D entity = await uow.Repository <D>().GetByID(model.ID); if (entity == null) { return new APIResult() { Data = model.ID, Message = Messages.GNE0001 } } ; if (entity is ITableEntity <Y> ) { ///Access Control if (userID != null && checkAuthorize) { if (!(entity as ITableEntity <Y>).CreateBy.Equals(userID.Value)) { return new APIResult() { Data = model.ID, Message = Messages.GNW0001 } } ; } (entity as ITableEntity <Y>).UpdateDT = DateTime.Now; (entity as ITableEntity <Y>).UpdateBy = userID.Value; } Mapper.Map(model, entity); if (isCommit) { await uow.SaveChangesAsync(); } return(new APIResult() { Data = entity.ID, Message = Messages.Ok }); }
public virtual async Task <APIResult> Delete(Y id, Y?userId = default(Y?), bool isCommit = true, bool checkAuthorize = false) { D entity = await _uow.Repository <D>().GetById(id); if (entity == null) { return new APIResult() { Data = id, Message = Messages.GNE0001 } } ; if (entity is ITableEntity <Y> ) { //Access Control if (userId != null && checkAuthorize) { if (!(entity as ITableEntity <Y>).CreateBy.Equals(userId.Value)) { return new APIResult() { Message = Messages.GNW0001 } } } ; (entity as ITableEntity <Y>).UpdateDT = DateTime.Now; (entity as ITableEntity <Y>).UpdateBy = userId.Value; } entity.IsDeleted = true; if (isCommit) { await _uow.SaveChangesAsync(); } return(new APIResult() { Data = id, Message = Messages.Ok }); }
public virtual async Task <G> GetByID(Y id, Y?userId = null, bool isDeleted = false) { try { IQueryable <D> query = _uow.Repository <D>().Query(isDeleted).Where(Predicate.Equal <D, Y>("ID", id)); if (userId != null) { query = query.Equal("CreateByID", userId.Value); } G data = await query.ProjectTo <G>().FirstOrDefaultAsync(); return(data); } catch (Exception ex) { return(null); } }
public virtual async Task <IList <AutoCompleteListVM <Y> > > AutoCompleteList(Y?id = default(Y?), string text = default(string)) { var query = uow.Repository <D>().Query().ProjectTo <AutoCompleteList <Y> >().AsQueryable(); var pkType = default(Y); if ((pkType is Guid && !(id as Guid?).IsNullOrEmpty()) || id != null) { query = query.Where(x => (object)x.ID == (object)id); } if (text != null) { query = query.Where(x => x.Search.Contains(text)); } return(await query.OrderBy(x => x.Text).ProjectTo <AutoCompleteListVM <Y> >().ToListAsync()); }