public void Add(Research value) { var model = ResearchService.Add(); model.Item = value; Add(model); }
public async Task <bool> DeleteServiceAsync(int labid, int serviceid) { Laboratory laboratory = await unitOfWork.Laboratories.Where(l => l.Id == labid).SingleOrDefaultAsync(); if (laboratory == default(Laboratory)) { throw new RequestError("Laboratory doesn't exist!"); } // AUTHORISATION CHECK int myId = authService.CurrentUser.Id; if (myId != laboratory.Coordinator.Id && !laboratory.Permissions.Any(p => p.UserId == myId)) { throw new RequestError(403, "Permission denied!"); } ResearchService researchService = laboratory.ResearchServices.Where(rs => rs.Id == serviceid).SingleOrDefault(); if (researchService == default(ResearchService)) { throw new RequestError(404, "Equipment does not exist!"); } laboratory.ResearchServices.Remove(researchService); await unitOfWork.SaveAsync(); return(true); }
public async Task <bool> CreateServiceAsync(int laboratoryId, CreateServiceRequest request) { ResearchServiceType type; if (!Enum.TryParse(request.Type, true, out type)) { throw new RequestError("Service type is invalid!"); } if (request.Name.Length == 0) { throw new RequestError("Name can not be empty"); } if (request.Name.Length > 200) { throw new RequestError("Name can not be longer than 200"); } Laboratory laboratory = await unitOfWork.Laboratories.Where(l => l.Id == laboratoryId).SingleOrDefaultAsync(); if (laboratory == default(Laboratory)) { throw new RequestError("Non existing laboratory"); } // AUTHORISATION CHECK int myId = authService.CurrentUser.Id; if (myId != laboratory.Coordinator.Id && laboratory.Permissions.Where(p => p.UserId == myId).SingleOrDefault() == default(LaboratoryPermission)) { throw new RequestError(403, "Permission denied!"); } List <User> team = new List <User>(); foreach (int teamMember in request.Persons) { var user = await unitOfWork.Users.Where(u => u.Id == teamMember).SingleOrDefaultAsync(); if (user == default(User)) { throw new RequestError("Team member does not exist!"); } team.Add(user); } ResearchService researchService = new ResearchService { Laboratory = laboratory, Description = request.Description, Name = request.Name, Type = type }; researchService.Persons = team.Select(t => new ResearchServicePerson { User = t, ResearchService = researchService }).ToList(); laboratory.ResearchServices.Add(researchService); await unitOfWork.SaveAsync(); return(true); }
public void Edit(int id) { var model = ResearchService.Edit(id); var window = new AddEditResearch(this); window.Render(model); window.ShowDialog(); }
public void Save(ResearchModel model) { ResearchService.Save(model); if (View == null) { return; } RenderDocument(); View.UpdateView(model); }
public void Delete(int id) { var model = ResearchService.Delete(id); if (View == null) { return; } RenderDocument(); View.UpdateView(model); }
public void Add() { Add(ResearchService.Add()); }
public override ResearchCacheData GetModel() { return(ResearchService.GetModel()); }