public ReturnObject GetOne(long id) { try { var data = new DonationRepository().GetOne(id); return(new ReturnObject { Data = data, Msg = "Record retrieved successfully", Status = 1, Total = 1 }); } catch (Exception e) { return(new ReturnObject { Data = null, Msg = e.Message, Status = 0, Total = 0 }); } }
public ReturnObject GetAll() { try { var data = new DonationRepository().GetAll(); return(new ReturnObject { Data = data, Msg = "Records retrieved Sucessfully", Status = 1, Total = data.Count() }); } catch (Exception e) { return(new ReturnObject { Data = null, Msg = e.Message, Status = 0, Total = 0 }); } }
public ReturnObject Delete(long donationId) { try { var data = new DonationRepository().Delete(donationId); if (data != true) { throw new Exception("Could not delete region"); } return(new ReturnObject { Data = null, Msg = "Deleted Sucessfully", Status = 1, Total = 1 }); } catch (Exception e) { return(new ReturnObject { Data = null, Msg = e.Message, Status = 0, Total = 0 }); } }
public DonationListViewModel(DonationStatus status) { this.donationRepository = new DonationRepository(); Title = (status == DonationStatus.PendingPickup? "Pending " : status.ToString("G")) + " Donations"; Items = new ObservableCollection <Donation>(); LoadItemsCommand = new Command(async() => await ExecuteLoadItemsAsync(status), () => !IsBusy); }
public AcceptedItemsViewModel() { LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); donationRep = new DonationRepository(); GroupedItems = new ObservableCollection <Group>(); Title = "Accepted Donations"; }
public ReturnObject Create(Donation donation) { try { var data = new DonationRepository().AddDonations(donation); if (data != true) { throw new Exception("Couldn't save the region"); } return(new ReturnObject { Data = null, Msg = "Saved Successfully", Status = 1, Total = 1 }); } catch (Exception e) { return(new ReturnObject { Data = null, Msg = e.Message, Status = 0, Total = 0 }); } }
public DonationListViewModel() { this.donationRepository = new DonationRepository(); Title = "My Donations"; Items = new ObservableCollection<Group>(); LoadItemsCommand = new Command(async () => await ExecuteLoadItemsAsync(), () => !IsBusy); }
public static DonationController GetDonationController() { var context = TestHelpers.CreateContext(); var eventRepository = new DonationRepository(context, TestHelpers.AspenMapper); var loggerMock = new Mock <ILogger <DonationController> >(); return(new DonationController(eventRepository, TestHelpers.AspenMapper, loggerMock.Object)); }
public static AdminController GetAdminController() { var context = TestHelpers.CreateContext(); var donationRepository = new DonationRepository(context, TestHelpers.AspenMapper); var eventRepository = new EventRepository(context, TestHelpers.AspenMapper); return(new AdminController(donationRepository, eventRepository, TestHelpers.AspenMapper)); }
public async Task <IEnumerable <DonationResponseDto> > GetAllDonation(Expression <Func <Donation, bool> > predicate) { IQueryable <Donation> donation = DonationRepository.GetWhereAsQueryable(predicate).Include(d => d.CharitableEntity).Include(d => d.DonationItem).OrderByDescending(g => g.Date); IEnumerable <DonationResponseDto> donationResponse = this.Mapper.Map <IEnumerable <DonationResponseDto> >(await donation.ToListAsync()); return(donationResponse); }
public AcceptedDetailViewModel(Donation item = null) { Title = item?.Title; Item = item; donationRep = new DonationRepository(); CancelCommand = new Command(async() => await ExecuteCancelCommand(), () => CanCancel()); }
public RelistViewModel(int id) { donationRep = new DonationRepository(); PageTitle = "Edit Item"; EnterText = "Relist"; EnterCommand = new Command(async() => await ExecuteRelistCommand(id), () => !IsBusy); LoadDonationCommand = new Command(async() => await ExecuteLoadDonations(id)); TakePictureCommand = new Command(async() => await ExecuteTakePicture()); }
public AcceptedItemsViewModel(DonationStatus status) { LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand(status)); donationRep = new DonationRepository(); Items = new ObservableCollection <Donation>(); string statusString = status == DonationStatus.PendingPickup ? "Pending Pickup" : status.ToString("G"); Title = statusString; }
public async Task <PagedResponse <DonationResponseDto> > GetAllDonation(Expression <Func <Donation, bool> > predicate, PaginationParams paginationParams) { IQueryable <Donation> donation = DonationRepository.GetWhereAsQueryable(predicate).Include(d => d.CharitableEntity).Include(d => d.DonationItem).OrderByDescending(g => g.Date); PagedResponse <DonationResponseDto> pagedResponse = new PagedResponse <DonationResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(donation, paginationParams, this.Mapper.Map <IEnumerable <DonationResponseDto> >); return(pagedResponse); }
public async Task <PagedResponse <DonationResponseDto> > GetAllDonation(PaginationParams paginationParams) { IQueryable <Donation> donation = DonationRepository.GetAllAsQueryable().OrderBy(g => g.Date); PagedResponse <DonationResponseDto> pagedResponse = new PagedResponse <DonationResponseDto>(); pagedResponse = await pagedResponse.ToPagedResponse(donation, paginationParams, this.Mapper.Map <IEnumerable <DonationResponseDto> >); return(pagedResponse); }
public DonationDetailViewModel(Donation item) { Title = item?.Title; Item = item; donationRepository = new DonationRepository(); CompleteCommand = new Command(async() => await CompleteDonationAsync(item.Id), () => CanCompleteDonation(item.Status)); WasteCommand = new Command(async() => await WasteDonationAsync(item.Id), () => CanWasteDonation(item.Status)); RelistCommand = new Command(async() => await RelistDonationAsync(item.Id), () => CanRelistDonation(item.Status)); }
public DonationViewModel() { PageTitle = "New Item"; EnterCommand = new Command(async() => await SaveDonationAsync(), () => !IsBusy && App.User.Verified); TakePictureCommand = new Command(async() => await TakePictureAsync()); ExpirationDate = DateTime.Now; //Default to 2 hour expiration var expiration = DateTime.Now.AddHours(2); ExpirationTime = new TimeSpan(expiration.Hour, expiration.Minute, expiration.Second); donationRepository = new DonationRepository(); }
public async Task <bool> ExistDonation(Expression <Func <Donation, bool> > predicate) { List <Donation> lstDonation = null; var query = DonationRepository.GetWhereAsQueryable(predicate); lstDonation = await query.ToListAsync(); var donation = lstDonation.FirstOrDefault(); if (donation == null) { return(false); } return(true); }
public string Get(int vkId, string type) { string result = ResultHelper.Error(ExceptionEnum.WrongRequest); List <DAL.Donation> donations = DonationRepository.GetDonationByVkId(vkId); if (donations == null) { return(ResultHelper.Error(ExceptionEnum.DBException)); } switch (type) { //получить все успешные донации case "successful": List <DAL.Donation> successDonations = donations.Where(d => d.donation_success == true).ToList(); result = JsonConvert.SerializeObject(successDonations); break; //текущий timeline, в котором пользователь находится case "timeline": //если есть таймлайн в процессе (не finished) - выдаём его DAL.Donation timelineDonation = donations.Where(d => d.finished == false).ToList().LastOrDefault(); //если в процессе таймлайна нет - создаём его if (timelineDonation == null) { //вычислить дату после которой донор может записаться на донацию DateTime appointmentFrom = DateTime.Now; DAL.User user = UserRepository.GetUserByVkId(vkId); if (user != null && user.donor_pause_to.HasValue && user.donor_pause_to.Value > DateTime.Now) { appointmentFrom = UserRepository.GetUserByVkId(vkId).donor_pause_to.Value; } DAL.Donation newAppointment = new DAL.Donation() { vk_id = vkId, appointment_date_from = appointmentFrom, appointment_date_to = appointmentFrom.AddDays(7) }; timelineDonation = newAppointment; DonationRepository.AddDonation(timelineDonation); } result = JsonConvert.SerializeObject(timelineDonation); break; } return(result); }
public AcceptedDetailViewModel(Donation item = null) { Title = item?.Title; Item = item; donationRep = new DonationRepository(); OptionsCommand = new Command(ExecuteOptionsCommand); if (String.IsNullOrWhiteSpace(item.PictureUrl) || String.Equals(item.PictureUrl, "Empty")) { item.PictureUrl = null; HasImage = false; } else { HasImage = true; } }
public async Task <DonationResponseDto> GetDonation(Expression <Func <Donation, bool> > predicate) { List <Donation> lstDonation = null; var query = DonationRepository.GetWhereAsQueryable(predicate); lstDonation = await query.ToListAsync(); var donation = lstDonation.FirstOrDefault(); if (donation == null) { return(null); } var donationDto = this.Mapper.Map <DonationResponseDto>(donation); return(donationDto); }
public RelistViewModel(Donation donation) { donationRep = new DonationRepository(); PageTitle = "Edit Item"; EnterCommand = new Command(async() => await ExecuteRelistCommand(), () => !IsBusy); TakePictureCommand = new Command(async() => await ExecuteTakePicture()); ImageSource = donation.PictureUrl; DonationTitle = donation.Title; Quantity = donation.Amount; DonationType = donation.Type.ToString(); var expiration = GetExpiration(donation.Expiration.Value); ExpirationDate = expiration.Date; ExpirationTime = new TimeSpan(expiration.Hour, expiration.Minute, expiration.Second); this.donation = donation; }
public string Post(int vkId, int donationId, string type) { string result = ResultHelper.Success(); if (vkId == 0) { return(ResultHelper.Error(ExceptionEnum.EmptyNonRequiredParameter, "vkId")); } if (donationId == 0) { return(ResultHelper.Error(ExceptionEnum.EmptyNonRequiredParameter, "donationId")); } DAL.Donation newDonation = DonationRepository.DeleteAndAddNewDonation(donationId); result = JsonConvert.SerializeObject(newDonation); return(result); }
public string Post([FromBody] JObject donationJson) { string result; DAL.Donation donation = donationJson.ToObject <DAL.Donation>(); #region Проверка заполненности обязательных полей if (donation.vk_id == 0) { return(ResultHelper.Error(ExceptionEnum.EmptyNonRequiredParameter, "vk_id")); } #endregion DonationRepository.UpdateDonation(donation); //Когда пользователь посетит центр и сделает донацию или сдаст кровь из пальца (повторно) if (donation.confirm_visit != null && donation.confirm_visit.success != null && donation.confirm_visit.without_donation != null) { //вернуть новую запись с заполненными полями(appointment_date_from, appointment_date_to, previous_donation_date) //вычислить дату после которой донор может записаться на донацию DateTime appointmentFrom = UserRepository.GetUserByVkId(donation.vk_id).donor_pause_to.HasValue ? UserRepository.GetUserByVkId(donation.vk_id).donor_pause_to.Value : DateTime.Now; //предыдущую дату выдачи проставляем только если была успешная сдача в этой DateTime?previous_success_date = null; if (donation.donation_date.HasValue && donation.donation_success == true) { previous_success_date = donation.donation_date.Value; } DAL.Donation newAppointment = new DAL.Donation() { vk_id = donation.vk_id, appointment_date_from = appointmentFrom, appointment_date_to = appointmentFrom.AddDays(7), previous_donation_date = previous_success_date }; //Если success = true + without_donation = false из старого объекта скопируется центр if (donation.confirm_visit.success == true && donation.confirm_visit.without_donation == false) { newAppointment.station_id = donation.station_id; newAppointment.station_address = donation.station_address; newAppointment.station_title = donation.station_title; } donation = newAppointment; DonationRepository.AddDonation(donation); } result = JsonConvert.SerializeObject(donation); return(result); }
static void Main(string[] args) { VolunteerRepository volunteerRepository = new VolunteerRepository(); VolunteerService volunteerService = new VolunteerService(volunteerRepository); DonorRepository donorRepository = new DonorRepository(); DonationRepository donationRepository = new DonationRepository(); CaseRepository caseRepository = new CaseRepository(); DonationService donationService = new DonationService(caseRepository, donorRepository, donationRepository); // Volunteer volunteer = volunteerRepository.FindOne("admin", "admin"); // Console.WriteLine("voluntar: "+volunteer.Username); ServerService serverService = new ServerService(volunteerService, donationService); SerialServer server = new SerialServer("127.0.0.1", 55555, serverService); server.Start(); Console.WriteLine("Server started... "); //Console.WriteLine("Press <enter> to exit..."); Console.ReadLine(); }
public async Task ApproveDonation(Guid id) { var donationAsync = await DonationRepository.GetWhereAsync(p => p.Id == id); var donation = donationAsync.FirstOrDefault(); if (donation == null) { throw new Exception($"Donation id ${id} was not found"); } if (donation.Total > 0) { throw new Exception($"Online donation cannot be canceled by this function"); } donation.Canceled = false; donation.Completed = true; this.DonationRepository.Udate(donation); await this.DonationRepository.SaveAsync(); }
public static async Task <string> GetBloodStationsByVkIdTask(int vkId) { var apiKey = ConfigurationManager.AppSetting["AppSettings:DonorSearchApiKey"]; var apiPath = ConfigurationManager.AppSetting["AppSettings:DonorSearchApiPath"]; string stationsJson; //var currentUserJson = await DSUser.GetUserByVKId(vkId); //var currentUser = JsonConvert.DeserializeObject<DAL.User>(currentUserJson); var currentUser = UserRepository.GetUserByVkId(vkId); var cityId = currentUser.city_id; if (!cityId.HasValue || cityId == 0) { return("[]"); } using (var graphQlClient = new GraphQLClient(apiPath + apiKey)) { var stationsRequest = new GraphQLRequest { Query = @"query blood_stations($city_id: Int) { blood_stations(city_id: $city_id) { accept_first_timers address blood_type_name can_get_pdr city { id title } created_at email errors { key } fax id lat lng need_requests { blood_type { created_at display_title id title updated_at } end_time id intensity is_disabled start_time when_is_it } no_registration phones site title updated_at without_registration works_on_monday works_on_tuesday works_on_wednesday works_on_thursday works_on_friday works_on_saturday works_on_sunday } }", OperationName = "blood_stations", Variables = new { city_id = cityId //TODO query } }; var graphQlResponse = await graphQlClient.PostAsync(stationsRequest); var stations = graphQlResponse.GetDataFieldAs <List <DSBloodStation> >("blood_stations"); foreach (var station in stations) { //station.requrement_of_user_blood = GetRandomNumber(0,2); //check if station accepts first timers station.accept_first_timers = DonationRepository.GetDonationByVkId(currentUser.vk_id) .All(c => cityId != currentUser.city_id); var necessity = currentUser.CheckForBloodNeccesity(station.need_requests); //chech for requirement of blood for current user if (necessity >= 50) { station.requrement_of_user_blood = -2; } if (necessity < 50) { station.requrement_of_user_blood = -1; } if (necessity == 0) { station.requrement_of_user_blood = 0; } //check if station accepts users without registration if (currentUser.has_registration.HasValue && !currentUser.has_registration.Value && station.without_registration.Value) { station.requrement_of_user_blood = 0; } } stationsJson = JsonConvert.SerializeObject(stations); } return(stationsJson); }
public void Setup() { _ctx.Database.Delete(); _repository = new DonationRepository(_ctx); }
public void Setup() { _memoryStream = new MemoryStream(); _db = new LiteDatabase(_memoryStream); _donationRepository = new DonationRepository(_db); }
public DonationService() { donationRepository = new DonationRepository(); }