public IHttpActionResult Put(int id, ListUpdateTO listUpdate) { if (id > 0) { string identityUserName = System.Web.HttpContext.Current.User.Identity.Name; //check if list exists bool exists = _listService.CheckIfListExists(id); if (!exists) { return(BadRequest(ListENUM.LIST_NOT_FOUND.ToString())); } bool isModerator = System.Web.HttpContext.Current.User.IsInRole("Moderator"); if (!isModerator) { //check if list belongs to logged user string listCreator = _listService.GetListCreator(id); if (listCreator != identityUserName) { return(BadRequest(ListENUM.UNABLE_UPDATE_LIST_USER_IS_NOT_CREATOR.ToString())); } } //check if all films exists if (listUpdate.FilmIds != null) { foreach (var film in listUpdate.FilmIds) { bool filmExists = _filmService.CheckIfFilmExists(film); if (!filmExists) { return(BadRequest(FilmENUM.FILM_NOT_FOUND.ToString())); } } } try { var success = _listService.UpdateList(id, listUpdate); if (success == true) { logger.Log(LogLevel.Info, "List with id: " + id + " was updated.\n"); return(StatusCode(HttpStatusCode.Created)); } } catch (Exception ex) { logger.Log(LogLevel.Error, ex); } } logger.Log(LogLevel.Error, "Unable to update list.\n"); return(BadRequest(ListENUM.UNABLE_UPDATE_LIST.ToString())); }
public bool UpdateList(int listId, ListUpdateTO listUpdate) { if (listUpdate != null) { using (var scope = new TransactionScope()) { var result = _listRepository.UpdateList(listId, listUpdate.Name, listUpdate.FilmIds); if (result == false) { return(false); } addNewestListToCache(listId, true); scope.Complete(); return(true); } } return(false); }