public async Task <string> Post([FromBody] JObject userJson, string type) { string result; //check right format for JSON - TODO validation failed //string userSchemaJson = JsonConvert.SerializeObject(new DAL.User()); //JSchema schema = JSchema.Parse(userSchemaJson); //if (!userJson.IsValid(schema)) //{ // return JsonConvert.SerializeObject(new Result(false, ExceptionEnum.NotRightJSONFormat.ToString())); //} DAL.User user = userJson.ToObject <DAL.User>(); //считаем, что формат неправильный if (user.vk_id == 0 || string.IsNullOrEmpty(user.first_name) || string.IsNullOrEmpty(user.last_name)) { return(ResultHelper.Error(ExceptionEnum.NotRightJSONFormat)); } #region Проверка заполненности обязательных полей if (user.vk_id == 0) { return(ResultHelper.Error(ExceptionEnum.EmptyNonRequiredParameter, "vk_id")); } if (string.IsNullOrEmpty(user.first_name)) { return(ResultHelper.Error(ExceptionEnum.EmptyNonRequiredParameter, "first_name")); } if (string.IsNullOrEmpty(user.last_name)) { return(ResultHelper.Error(ExceptionEnum.EmptyNonRequiredParameter, "last_name")); } if (string.IsNullOrEmpty(user.city_title)) { return(ResultHelper.Error(ExceptionEnum.EmptyNonRequiredParameter, "city_title")); } #endregion User resultUser = await UserRepository.AddOrUpdateUser(user, type == "init"); result = JsonConvert.SerializeObject(resultUser); //update in APi - not work //mutation updateProfile($first_name: String, $second_name: String, $last_name: String, $maiden_name: String, $bdate: Int, $gender: Int, $city_id: Int, $about_self:String, $blood_type_id:Int, $kell: Int, $blood_class_ids:[Int],$bone_marrow: Boolean, $cant_to_be_donor: Boolean, $donor_pause_to: Int ) //{ // updateProfile(first_name: $first_name, second_name: $second_name, last_name:$last_name, maiden_name:$maiden_name, bdate:$bdate, gender:$gender, city_id:$city_id, about_self:$about_self, blood_type_id:$blood_type_id, kell:$kell, blood_class_ids:$blood_class_ids, bone_marrow:$bone_marrow, cant_to_be_donor:$cant_to_be_donor, donor_pause_to:$donor_pause_to) //{ id first_name last_name second_name} //} return(result); }
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 string Get(int vkId) { //From Api //return Content(await UserApi.GetUserByVKId(vkId)); string result; DAL.User user = UserRepository.GetUserByVkId(vkId); if (user == null) { result = ResultHelper.Error(ExceptionEnum.DBException); } else { result = JsonConvert.SerializeObject(user); } return(result); }
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); }
public async Task <string> GetAsync(int vkId) { //From Api //return Content(await UserApi.GetUserByVKId(vkId)); string result; DAL.User user = UserRepository.GetUserByVkId(vkId); var coordinates = await OsmLocation.GetCoordinatesByCityTitleTask(user); if (user == null) { result = ResultHelper.Error(ExceptionEnum.DBException); } else { result = coordinates; } return(result); }