/// <summary> /// Проверить день рождения. /// </summary> private void CheckBirthday() { if (_project.BirthdayList().Count == 0) { BirthdayListBox.Hide(); BirthdayList.Hide(); return; } BirthdayListBox.DisplayMember = "Surname"; BirthdayListBox.DataSource = _project.BirthdayList(); }
public async Task BirthdayCommand(string date) { var tomorrow = DateTime.Today.AddDays(1).ToString("M/d"); var today = DateTime.Today.ToString("M/d"); var dateParsed = DateTime.Parse(date).ToString("M/d"); PronounList pronouns; using (StreamReader file = File.OpenText("pronouns.json")) { JsonSerializer serializer = new JsonSerializer(); pronouns = (PronounList)serializer.Deserialize(file, typeof(PronounList)); file.Close(); } pronouns.pronounsList.TryGetValue(Context.User.Id.ToString(), out string myPronouns); if (myPronouns == null) { myPronouns = "2"; } using (StreamReader file = File.OpenText("birthdays.json")) { JsonSerializer serializer = new JsonSerializer(); BirthdayList birthdays = (BirthdayList)serializer.Deserialize(file, typeof(BirthdayList)); birthdays.birthdaysList[Context.Message.Author.Id.ToString()] = date; file.Close(); using (StreamWriter sw = new StreamWriter("birthdays.json")) using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, birthdays); sw.Close(); } } if (dateParsed == today) { await ReplyAsync("Ok, so your birthday is **" + FormattedDate(date) + "**? I'll remember that! Wait...whoa! That means your birthday is today! Hey @here it's " + Context.User.Mention + "'s birthday today! " + Helpers.FirstLetterToUpper(pronouns.pronounTypes[int.Parse(myPronouns)][0] as string) + " is " + (Helpers.GetAge(DateTime.Parse(date)) + 1) + " years old today! :birthday:"); } else if (dateParsed == tomorrow) { await ReplyAsync("Ok, so your birthday is **" + FormattedDate(date) + "**? I'll remember that! Wait...whoa! That means your birthday is tomorrow! Hey @here it's " + Context.User.Mention + "'s birthday tomorrow! " + Helpers.FirstLetterToUpper(pronouns.pronounTypes[int.Parse(myPronouns)][0] as string) + " will be " + (Helpers.GetAge(DateTime.Parse(date)) + 1) + " years old! :birthday: Let's all wish " + pronouns.pronounTypes[int.Parse(myPronouns)][1] + " a happy birthday when the time comes!"); } else { await ReplyAsync("Ok, so your birthday is **" + FormattedDate(date) + "**? I'll remember that!"); } Helpers.ConsoleControl.WriteOutput(DateTime.Now.ToString() + " - Setting birthday for User " + Context.Message.Author.Username + " (" + Context.Message.Author.Id.ToString() + ") to " + FormattedDate(date) + "\n", System.Drawing.Color.White); }
public HttpResponseMessage Post([FromBody] BirthdayListRequest request) { BirthdayList BirthdayList = new BirthdayList(); string baseUrl = Url.Request.RequestUri.GetComponents( UriComponents.SchemeAndServer, UriFormat.Unescaped); try { if (request.userid != "" && request.userid != null) { var birthdaylist = GInfraEntities.GetBirthdayData(request.userid).ToList(); //var list = GInfraEntities.sp_hrnotification().ToList(); if (birthdaylist.Count > 0) { foreach (var item in birthdaylist) { BirthdayListResponse BirthdayListResponse = new BirthdayListResponse(); BirthdayListResponse.EmployeeCode = item.EmployeeCode.ToString(); BirthdayListResponse.EmployeeName = item.EmployeeName; // BirthdayListResponse.BirthdayDate = String.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(item.BirthdayDate)); BirthdayListResponse.BirthdayDate = DateTime.Parse(item.BirthdayDate).ToString("MMM dd"); BirthdayListResponse.Branch = item.Branch; BirthdayListResponse.EmployeeMail = item.CmpMail; if (item.MangerID == "Null" && item.MangerID != null) { BirthdayListResponse.ReportingHeadId = "-"; } else { BirthdayListResponse.ReportingHeadId = item.MangerID.ToString(); } BirthdayList.Birthday.Add(BirthdayListResponse); } BirthdayList.Status = true; BirthdayList.Message = "Birthday list fetch succefully"; return(Request.CreateResponse(HttpStatusCode.OK, BirthdayList)); } else { BirthdayList.Status = false; BirthdayList.Message = "No Records Found"; return(Request.CreateResponse(HttpStatusCode.OK, BirthdayList)); } //if (list.Count > 0) //{ // foreach (var k in list) // { // HrResponse HrResponse = new HrResponse(); // HrResponse.Image = baseUrl + k.Image.ToString(); // if (k.Image != "-" && k.Image != null && k.Image != "") // { // HrResponse.Image = baseUrl + k.Image.ToString(); // } // else // { // HrResponse.Image = "-"; // } // HrResponse.Title = k.Title.ToString(); // HrResponse.Description = k.Description.ToString(); // BirthdayList.HrNotification.Add(HrResponse); // } // //BirthdayList.Status = true; // //BirthdayList.Message = "List Fetch Successfully"; // //return Request.CreateResponse(HttpStatusCode.OK, BirthdayList); //} //else //{ // //BirthdayList.Status = false; // //BirthdayList.Message = "No Records Found"; // // return Request.CreateResponse(HttpStatusCode.OK, BirthdayList); //} } else { BirthdayList.Status = false; BirthdayList.Message = "Bad request"; return(Request.CreateResponse(HttpStatusCode.OK, BirthdayList)); } //return Request.CreateResponse(HttpStatusCode.OK, BirthdayList); } catch (Exception ex) { //BirthdayList.Status = false; //BirthdayList.Message = "" + ex.Message + ""; return(Request.CreateResponse(HttpStatusCode.InternalServerError, BirthdayList)); } }