Example #1
0
        public async Task <bool> CreateContactInformationAsync(int id, CreateContactInformationRequest request)
        {
            Laboratory laboratory = await unitOfWork.Laboratories.Where(l => l.Id == id).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.Where(p => p.UserId == myId).SingleOrDefault() == default(LaboratoryPermission))
            {
                throw new RequestError(403, "Permission denied!");
            }

            string res = request.Validate();

            if (res != "")
            {
                throw new RequestError(res);
            }
            var temp = new ContactInformation
            {
                Content = request.Content,
                Type    = Enum.Parse <ContactInformationType>(request.Type, true)
            };

            laboratory.ContactInformation.Add(temp);
            await unitOfWork.SaveAsync();

            return(true);
        }
Example #2
0
 public async Task <bool> CreateContactInformationAsync([FromRoute] int id, [FromBody] CreateContactInformationRequest request)
 {
     return(await laboratoryService.CreateContactInformationAsync(id, request));
 }