Solved

Turn this into Linq

Posted on 2014-03-03
5
198 Views
Last Modified: 2016-02-10
Can this be turned into Linq to make it less ugly?


if (_now > DateTime.Today && _now < DateTime.Today.AddHours(10).AddMinutes(30))
                        {
                            _medPass = "AM";

                            ts = slots.GetSlot(TimeSlotType.AM);
                            MainForm.CurrentInstance.ShowMedPass(ts, MedPassMode.NORMAL, CartGroup.Med, patient);
                            break;
                        }

                        else if (_now > DateTime.Today.AddHours(10).AddMinutes(30) &&
                                 _now < DateTime.Today.AddHours(13).AddMinutes(30))
                        {
                            _medPass = "NOON";

                            ts = slots.GetSlot(TimeSlotType.NOON);
                            MainForm.CurrentInstance.ShowMedPass(ts, MedPassMode.NORMAL, CartGroup.Med, patient);
                            break;
                        }

                        else if (_now > DateTime.Today.AddHours(13).AddMinutes(30) &&
                                 _now < DateTime.Today.AddHours(18).AddMinutes(59))
                        {
                            _medPass = "PM";

                            ts = slots.GetSlot(TimeSlotType.PM);
                            MainForm.CurrentInstance.ShowMedPass(ts, MedPassMode.NORMAL, CartGroup.Med,
                                patient);
                            break;
                        }

Open in new window

0
Comment
Question by:rawinnlnx9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39900743
What do you think LINQ was designed to do? (I'm not trying to be a smart-ass; I really want to understand what you know about LINQ!)
0
 
LVL 9

Author Comment

by:rawinnlnx9
ID: 39900771
I'm actually trying to learn it. I want to figure out a way to use the FirstOrDefault to improve the query and get rid of the if/elseif. I think that there's a more elegant way to do this but my attemps have been tossed out as rubbish by the compiler.

Aside from that I don't know how else to answer your question. Linq is new to me and I need to start using it more.
0
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 0 total points
ID: 39900838
Figured it out. C# does the heavy lifting for you if you just ask nicely.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39900851
No worries. The reason I asked was because nothing in your code jumped out at me as being LINQ-friendly. But I attribute that more to not knowing the types of each object rather than your code structure. LINQ can be a bit of fun when you get to the more advanced features of it. Keep at it  = )
0
 
LVL 9

Author Closing Comment

by:rawinnlnx9
ID: 39914450
I answered it myself. What other grade would I give?
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question