?
Solved

Turn this into Linq

Posted on 2014-03-03
5
Medium Priority
?
199 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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