public IHttpActionResult GetInteraction(int id) { try { UnitOfWork unitOfWork = new UnitOfWork(factory); InteractionDTO dto = unitOfWork.InteractionsRepository.Get(d => d.Id == id, includeProperties: @"InteractionMembers,InteractionMembers.Employee,InteractionMembers.Employee.EmployeePassports, InteractionActs,InteractionActs.Act,InteractionActs.InteractionActMembers,InteractionActs.InteractionActMembers.Employee,InteractionActs.InteractionActMembers.Employee.EmployeePassports, InteractionActs.InteractionActOrganizationMembers,InteractionActs.InteractionActOrganizationMembers.OrganizationContactPerson, InteractionStatusMovements,InteractionStatusMovements.Status,InteractionBroken,InteractionBroken.InteractionBrokenReason,InteractionSucceed,InteractionSucceed.Office" ).FirstOrDefault().ToDTO(); return(Ok(dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult PostInteraction(InteractionDTO interactionDTO) { if (interactionDTO == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } try { Interaction interaction = interactionDTO.FromDTO(); UnitOfWork unitOfWork = new UnitOfWork(factory); unitOfWork.InteractionsRepository.Insert(interaction); unitOfWork.Save(); Interaction toReturn = unitOfWork.InteractionsRepository.Get(d => d.Id == interaction.Id, includeProperties: @"InteractionMembers,InteractionMembers.Employee,InteractionMembers.Employee.EmployeePassports, InteractionActs,InteractionActs.Act,InteractionActs.InteractionActMembers,InteractionActs.InteractionActMembers.Employee,InteractionActs.InteractionActMembers.Employee.EmployeePassports, InteractionActs.InteractionActOrganizationMembers,InteractionActs.InteractionActOrganizationMembers.OrganizationContactPerson, InteractionStatusMovements,InteractionStatusMovements.Status" ).FirstOrDefault(); string userId = User.Identity.GetUserId(); EmployeeShortForm author = unitOfWork.EmployeesRepository .Get(d => d.AspNetUserId == userId, includeProperties: "EmployeePassports") .FirstOrDefault() .ToShortForm(); Notification notification = toReturn.ToAddingNotify(author); unitOfWork.NotificationsRepository.Insert(notification); unitOfWork.Save(); var context = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <NotificationHub>(); foreach (var item in notification.NotificationRecipients) { string employeeUserId = item.Employee.AspNetUserId; //context.Clients.User(employeeUserId).displayMessage(notification.NotificationText, notification.LinkName, notification.LinkId, notification.NotificationDate); context.Clients.All.displayMessage(notification.NotificationText, notification.LinkName, notification.LinkId, notification.NotificationDate); } InteractionDTO dto = toReturn.ToDTO(); return(CreatedAtRoute("GetInteraction", new { id = dto.Id }, dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }