Base solution for your next web application

Activities of "Dom1702"

Hi,

I have the following part of code:

 var filteredDrivingLessons = _drivingLessonRepository.GetAllIncluding(e => e.Instructors) // Instructors is a list for a many-to-many relationship
                        .WhereIf(!string.IsNullOrWhiteSpace(input.InstructorFilter), e => ContainsInstructor(e, input.InstructorFilter));

When debugging filteredDrivingLessons, the Instructors array is available and not null.

In the ContainsInstructor method however, the Instructors array is null. Why is that so?

What I am trying to achieve is passing an instructorFilter string that checks every entry in the Instructors array and compares first and last name.

Is there something in the WhereIf extension method not working as I expect it to or am I doing something completely wrong here?

Thank you!

Hi Maliming,

thanks for your help. This is the code:

 private bool ContainsInstructor(DrivingLesson dl, string filter)
        {
            if(dl.Instructors == null) // This is the part I always end up even though there are Instructors available
                return false;
        
            for (int i = 0; i < dl.Instructors.Count; i++)
            {
                if (dl.Instructors[i].Instructor.FirstName.Equals(filter) || dl.Instructors[i].Instructor.LastName.Equals(filter))
                    return true;
            }

            return false;
        }

And this is the actual method:

 public async Task<PagedResultDto<GetDrivingLessonForViewDto>> GetAll(GetAllDrivingLessonsInput input)
         {

            var filteredDrivingLessons = _drivingLessonRepository.GetAllIncluding(e => e.Instructors)
                        .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Topic.Contains(input.Filter))
                        .WhereIf(input.MinLengthFilter != null, e => e.Length >= input.MinLengthFilter)
                        .WhereIf(input.MaxLengthFilter != null, e => e.Length <= input.MaxLengthFilter)
                        .WhereIf(input.MinStartTimeFilter != null, e => e.StartTime >= input.MinStartTimeFilter)
                        .WhereIf(input.MaxStartTimeFilter != null, e => e.StartTime <= input.MaxStartTimeFilter)
                        .WhereIf(input.CompletedFilter > -1, e => Convert.ToInt32(e.Completed) == input.CompletedFilter)
                        .WhereIf(input.DrivingLessonTopicTopicFilter != null, e => e.Topic.Contains(input.DrivingLessonTopicTopicFilter))
                        .WhereIf(!string.IsNullOrWhiteSpace(input.InstructorFilter), e => ContainsInstructor(e, input.InstructorFilter));

            var query2 = (from o in filteredDrivingLessons

                          select new GetDrivingLessonForViewDto()
                          {
                              DrivingLesson = ObjectMapper.Map<DrivingLessonDto>(o),
                              StudentFullName = (o.StudentFk.FirstName == null || o.StudentFk.LastName == null) ? "" : o.StudentFk.FirstName + " " + o.StudentFk.LastName,
                              Description = o.Description,
                              Instructors = ObjectMapper.Map<IList<Instructors.Dtos.InstructorDto>>((from i in o.Instructors
                                                                                                     join i2 in _lookup_instructorRepository.GetAll() on i.InstructorId equals i2.Id
                                                                                                     select new Instructor() { Id = i2.Id, FirstName = i2.FirstName, LastName = i2.LastName }).ToList())
                          })
                        .WhereIf(!string.IsNullOrWhiteSpace(input.LicenseClassClassFilter), e => e.DrivingLesson.LicenseClass != null && e.DrivingLesson.LicenseClass.ToLower() == input.LicenseClassClassFilter.ToLower().Trim());


            var totalCount = await query2.CountAsync();

            var drivingLessons = await query2
                .OrderBy(input.Sorting ?? "drivingLesson.id asc")
                .PageBy(input)
                .ToListAsync();

            return new PagedResultDto<GetDrivingLessonForViewDto>(
                totalCount,
                drivingLessons
            );
         }

Thanks for your help. I really have no idea how to add this array to the query in way that I don't get the NullReferenceException.

I also tried to use the id in the ContainsInstructor method to get that one driving lesson from the repository, however then I get an exception telling me that I can't nest this query in another query because ef core does not allow this.

I'm not sure, what you mean.

What part of the project do you need?

Ah ok, it's not a big deal to upload my current project. Not much done. Can I just zip angular and asp net backend folders, upload it on my space and send you a link via mail?

I have the following issue. I am located in Germany, so right now my time is UTC+2.

The following happens: when I send for example a date with time 17:00 to the server using the swagger generated service proxy, it's saved in the database as 15:00 which is correct so far. As far as I can tell, it is converted using MomentJS in the service proxy.

However, when receiving the date, I cannot get it back to the local time. I tried calling moment.utc(receivedDate).local().toString() but this does nothing because if you check the isUTC boolean of the receivedDate it is already false, so it is considered converted already. But it's not. I just can't get it back to the local time. Should I use something else than moment to convert it back?

I'd also like to have a best practice guide or something similar

Hi,

no I'm not. I tried this approach but it's not working either. I cannot find any information about for example the ClockProvider class and how to handle time zones. Any documentation availabe for this I don't know of? The only thing I know for sure is that the service proxies generated by nswag convert time to UTC before sending it to the server. But after receiving the time from the server I just can't get it back to local time. Is this something that should already happen on the server side or is it handled completely by moment in the angular application?

Hey, thanks again for your help.

I did something different yesterday and it worked. First thing I noticed was, that there is no General tab in the host settings where I could change the timezone. It appeared after adding the line Clock.Provider = ClockProviders.Utc; to the Startup class. After setting the timezone it magically worked. Still don't know what's going on behind the scene though. I guess the moment framework uses the timezone setting and returns the appropriate time instead of UTC?

Question

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? Current
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? .Net Core

Hi,

after generating a new project and adding all my classes again on server and client side I face the following problem: Before I used the bootstrap grid system, but it no longer seems to work. Whatever margin I set there, it's not working, like

    <div class="col-md-3 col-sm-6 mb-3">
        <h6>{{l("Name")}} :</h6>
        {{student.firstName}} {{student.lastName}}
    </div>
  </div>
   </div>

<br> <br> Where can I find the css class names for building custom sites with proper margin, padding etc.? As far as I know, they switched from m- to kt- prefixes at some point, but now kt-* is also deprecated?

Best regards, Dominik

Answer

Hi ismcagdas,

sorry about that, mb-3 for example indeed works. So using bootstrap grid system is the way to go?

I am asking because in the past metronic had its own classes like "m--margin-top-20", but that is not woking anymore. Also when I use the ASP Net Zero Power Tools I get HTML with all sorts of classes like "form-group m-form__group align-items-center" or "input-group-btn". Is there any page where those classes are described?

Dominik

Showing 1 to 10 of 13 entries