public SingleResultModel<bool?> Delete(PerformanceRequestModel request) { ISecurityService securityService = ServiceFactory.CreateSecurityService(); IPerformanceService performanceService = ServiceFactory.CreatePerformanceService(); SingleResultModel<bool?> model = null; if ((model = HandleAuthentication<SingleResultModel<bool?>>()) == null) { model = new SingleResultModel<bool?> { Result = false }; try { if (securityService.Login(request.Username, request.Password) != null) { performanceService.Delete(request.Id); model.Result = true; } else { model.Error = "Login failed"; model.ErrorCode = (int)ErrorCode.LOGN_FAILED; } } catch (ServiceException e) { if (e.ErrorCode != null) { model.Error = GetMessageForPerformanceErrorCode(request.Language, e.ErrorCode); model.ServiceErrorCode = (int)e.ErrorCode; } else { model.Error = "Service throw error: " + e.Message; model.ServiceErrorCode = (int)ErrorCode.UNKNOWN_ERROR; } } catch (Exception e) { Console.WriteLine("Delete: Error during processing. error: " + e.Message); model.ErrorCode = (int)ErrorCode.UNKNOWN_ERROR; model.Error = ("Error during processing the request. error: " + e.Message); } finally { ServiceFactory.DisposeService(securityService); ServiceFactory.DisposeService(performanceService); } } return model; }
public SingleResultModel<PerformanceModel> Save(PerformanceRequestModel request) { ISecurityService securityService = ServiceFactory.CreateSecurityService(); IPerformanceService performanceService = ServiceFactory.CreatePerformanceService(); SingleResultModel<PerformanceModel> model = null; if ((model = HandleAuthentication<SingleResultModel<PerformanceModel>>()) == null) { IPerformanceDao performanceDao = DaoFactory.CreatePerformanceDao(); model = new SingleResultModel<PerformanceModel>(); try { User user = null; if ((user = securityService.Login(request.Username, request.Password)) != null) { model = new SingleResultModel<PerformanceModel>(); DateTime endDate = request.StartDate.Value.AddHours(1); Performance performance = null; if (request.Id != null) { performance = performanceDao.ById(request.Id); } performance = performanceService.Save(new Performance { Id = request.Id, Version = request.Version, ArtistId = request.ArtistId, VenueId = request.VenueId, StartDate = request.StartDate, EndDate = endDate, CreationUserId = (performance != null) ? performance.CreationUserId : user.Id, ModificationUserId = user.Id }, 1); model.Result = new PerformanceModel { Id = performance.Id.Value, Version = performance.Version.Value, StartDate = performance.StartDate.Value, EndDate = performance.EndDate.Value, Artist = new ArtistModel { Id = performance.ArtistId.Value }, Venue = new VenueModel { Id = performance.VenueId.Value } }; } else { model.Error = "Login failed"; model.ErrorCode = (int)ErrorCode.LOGN_FAILED; } } catch (ServiceException e) { if (e.ErrorCode != null) { model.Error = GetMessageForPerformanceErrorCode(request.Language, e.ErrorCode); model.ServiceErrorCode = (int)e.ErrorCode; } else { model.Error = "Service throw error: " + e.Message; model.ServiceErrorCode = (int)ErrorCode.UNKNOWN_ERROR; } } catch (Exception e) { Console.WriteLine("Save: Error during processing. error: " + e.Message); model.ErrorCode = (int)ErrorCode.UNKNOWN_ERROR; model.Error = ("Error during processing the request. error: " + e.Message); } finally { DaoFactory.DisposeDao(performanceDao); ServiceFactory.DisposeService(securityService); ServiceFactory.DisposeService(performanceService); } } return model; }