public HttpResponseMessage UpdatePlusOne(PlusOne plusOneToUpdate) { plusOneService.UpdatePlusOne(plusOneToUpdate); var responnse = Request.CreateResponse(HttpStatusCode.OK); return responnse; }
public PlusOneServiceResponseCodes AddPlusOne(int eventId, string username, string nameForPlusOne) { PlusOneServiceResponseCodes result; var eventToUpdate = uow.EventRepository.GetByID(eventId) as Event; var hostOfPlusOne = uow.UserRepository.Get(user => user.Username == username) as List<User>; // If the same name has already been used, return an error code. foreach (var plusOne in eventToUpdate.PlusOnes) { if (plusOne.Name == nameForPlusOne.ToLower()) { result = PlusOneServiceResponseCodes.CannotAddDuplicatePlusOnes; return result; } } // If the name hasn't been used, create a new plus one and add it to both event and user // Construct the plus one with the correct relational information var newPlusOne = new PlusOne() { Name = nameForPlusOne, EventId = eventId, UserId = hostOfPlusOne[0].UserId }; eventToUpdate.PlusOnes.Add(newPlusOne); hostOfPlusOne[0].PlusOnes.Add(newPlusOne); // Track the changes to be made to both repositories uow.EventRepository.Update(eventToUpdate); uow.UserRepository.Update(hostOfPlusOne[0]); // Committ the tracked changes for both repositories uow.Commit(); result = PlusOneServiceResponseCodes.OperationSuccessfull; return result; }
public PlusOneDTO(PlusOne plusOneToConvertToDTO) { if (plusOneToConvertToDTO != null) { PlusOneId = plusOneToConvertToDTO.PlusOneId; Name = plusOneToConvertToDTO.Name; UserId = plusOneToConvertToDTO.UserId; EventId = plusOneToConvertToDTO.EventId; } }