public static WebApiClasses.Classes.Category ToWebApi(Category category, wpContext context) { var mc = ToWebApi(category); if (mc == null) return null; var mcs = GetById(mc.Id, context); if (mcs == null) return mc; mc.Owner = User.ToWebApi(mcs.Owner); mc.CreatedBy = User.ToWebApi(mcs.CreatedBy); mc.Spring = Spring.ToWebApi(mcs.Spring); mc.Parent = ToWebApi(mcs.Parent); if(mcs.Subategories.Count > 0) mc.SubCategories = context.Categories .Where(c => c.ParentId.HasValue && c.ParentId.Value == mc.Id) .Select(c => ToWebApi(c, context)) .ToList(); return mc; }
public static WebApiClasses.Classes.Backlog ToWebApi(Backlog backlog, wpContext context) { var mb = ToWebApi(backlog); if (mb == null) return null; mb.CreatedBy = User.ToWebApi(User.GetById(mb.CreatedById, context), context); if(mb.AssignedToId.HasValue) mb.AssignedTo = User.ToWebApi(User.GetById(mb.AssignedToId.Value, context), context); mb.State = DictItem.ToWebApi(DictItem.GetById(mb.StateId, context)); mb.Type = DictItem.ToWebApi(DictItem.GetById(mb.TypeId, context)); mb.Category = Category.ToWebApi(Category.GetById(mb.CategoryId, context)); mb.Tasks = context.Tasks .Where(t => t.BacklogId == mb.Id && t.Deleted.GetValueOrDefault() == 0) .Select(t => Task.ToWebApi(t, context)) .ToList(); return mb; }
public static WebApiClasses.Classes.Spring ToWebApi(Spring spring, wpContext context) { var ms = ToWebApi(spring); if (ms == null) return null; var msp = GetById(spring.Id, context); if (msp == null) return ms; ms.Project = Project.ToWebApi(msp.Project); ms.Owner = User.ToWebApi(msp.Owner); ms.CreatedBy = User.ToWebApi(msp.CreatedBy); ms.Categories = context.Categories .Where(c => !c.ParentId.HasValue && c.SpringId == ms.Id && c.Deleted.GetValueOrDefault() == 0) .ToList() .Select(c => Category.ToWebApi(c, context)) .ToList(); return ms; }
private WebApiClasses.Classes.TaskAttachement ToWebApi(TaskAttachement taskAttachement, wpContext context, bool getFileContent = true) { var mta = ToWebApi(taskAttachement); if (mta == null) return null; mta.File = File.ToWebApi(context.Files.FirstOrDefault(f => f.Id == mta.FileId), getFileContent); return mta; }
public static Task GetById(int id, wpContext context) { try { return context.Tasks.FirstOrDefault(t => t.Id == id); } catch { return null; } }
public static User Login(string email, string pass, wpContext context) { pass = GenericLibrary.Helpers.Crypto.Hash.Md5(pass); User mu = context.Users.FirstOrDefault(u => u.Email == email && u.Word == pass); if(mu == null) throw new WpException("User or password is wrong"); if(mu.Suspended.GetValueOrDefault(0) == 1) throw new WpException("User is suspended"); return mu; }
public static WebApiClasses.Classes.Task ToWebApi(Task task, wpContext context) { var mt = ToWebApi(task); if (mt == null) return null; mt.CreatedBy = User.ToWebApi(User.GetById(mt.CreatedById, context), context); if(mt.AssignedToId.HasValue) mt.AssignedTo = User.ToWebApi(User.GetById(mt.AssignedToId.Value, context), context); mt.State = DictItem.ToWebApi(DictItem.GetById(mt.StateId, context)); mt.Type = DictItem.ToWebApi(DictItem.GetById(mt.TypeId, context)); if (mt.StageId.HasValue) mt.Stage = DictItem.ToWebApi(DictItem.GetById(mt.StageId.Value, context)); mt.Backlog = Backlog.ToWebApi(Backlog.GetById(mt.BacklogId, context)); return mt; }
public static TaskAttachement GetById(int id, wpContext context) { return context.TaskAttachements.FirstOrDefault(ta => ta.Id == id); }
public WebApiClasses.Classes.TaskAttachement ToWebApi(wpContext context, bool getFileContent = true) { return ToWebApi(this, context, getFileContent); }
public static Category GetById(int id, wpContext context) { return context.Categories.FirstOrDefault(c => c.Id == id); }
private static WebApiClasses.Classes.Task ToWebApiExtended(Task task, wpContext context) { var mtask = task.ToWebApi(context); FetchStrategy mfs = new FetchStrategy(); mfs.LoadWith<TaskAttachement>(f => f.File); mfs.LoadWith<File>(f => f.User); mfs.LoadWith<TaskAttachement>(f => f.User); mtask.Attachments = context.CreateDetachedCopy(context.TaskAttachements.Where(t => t.TaskId == mtask.Id).ToList(), mfs) .Select(ta => ta.ToWebApi(context, false)) .ToList(); mfs = new FetchStrategy(); mfs.LoadWith<TaskComment>(f => f.File); mfs.LoadWith<TaskComment>(f => f.User); mtask.Comments = context.CreateDetachedCopy(context.TaskComments.Where(tc => tc.TaskId == mtask.Id).ToList(), mfs) .Select(tc => tc.ToWebApi(false)) .ToList(); mfs = new FetchStrategy(); mfs.LoadWith<TaskDiscution>(f => f.File); mfs.LoadWith<TaskDiscution>(f => f.User); mtask.Discusion = context.CreateDetachedCopy(context.TaskDiscutions.Where(td => td.TaskId == mtask.Id).ToList(), mfs) .Select(td => td.ToWebApi(false)) .ToList(); mfs = new FetchStrategy(); mfs.LoadWith<TaskHistory>(f => f.User); mtask.Changes = context.CreateDetachedCopy(context.TaskHistories.Where(td => td.TaskId == mtask.Id).ToList(), mfs) .Select(th => th.ToWebApi()) .ToList(); return mtask; }
public WebApiClasses.Classes.Backlog ToWebApi(wpContext context) { return ToWebApi(this, context); }
public static SaveDataResponse Save(Backlog backlog, wpContext context) { try { if (backlog.Id == 0) context.Add(backlog); else { var mentity = GetById(backlog.Id, context); if(mentity == null) throw new WpException(WpErrors.ENTITY_NOT_FOUND, "Entity not found"); mentity.AssignedToId = backlog.AssignedToId; mentity.Name = backlog.Name; mentity.CreatedAt = backlog.CreatedAt; mentity.CreatedById = backlog.CreatedById; mentity.StateId = backlog.StateId; mentity.TypeId = backlog.TypeId; mentity.CategoryId = backlog.CategoryId; mentity.Priority = backlog.Priority; mentity.PeriodFrom = backlog.PeriodFrom; mentity.PeriodTo = backlog.PeriodTo; mentity.RemainingWork = backlog.RemainingWork; mentity.Description = backlog.Description; mentity.Metadata = backlog.Metadata; mentity.Tags = backlog.Tags; mentity.Deleted = backlog.Deleted; } return new SaveDataResponse(); } catch (Exception mex) { return new SaveDataResponse(mex); } }
public WebApiClasses.Classes.Task ToWebApiExtended(wpContext context) { return ToWebApiExtended(this, context); }
public static Backlog GetById(int id, wpContext context) { return context.Backlogs.FirstOrDefault(b => b.Id == id); }
public static Spring GetById(int id, wpContext context) { return context.Springs.FirstOrDefault(s => s.Id == id); }
public static DictItem GetById(int id, wpContext context) { return context.DictItems.FirstOrDefault(di => di.Id == id); }
public static TaskComment GetById(int id, wpContext context) { return context.TaskComments.FirstOrDefault(tc => tc.Id == id); }
public static User GetById(int uid, wpContext context) { return null;// context.Users.FirstOrDefault(u => u.Id == uid); }