angyLe
5/23/2017 - 8:26 AM

c# snippets

c# snippets

nameof(StaticPageContent.Html)
 // get httpContext service in validation filter or other
  IHttpContextAccessor httpContext = (IHttpContextAccessor)validationContext.GetService(typeof(IHttpContextAccessor));
  httpContext.HttpContext.Request.Path
  
  // in validation filter get from command value
  var containerType = validationContext.ObjectInstance.GetType();
            queriedType = (validationContext.ObjectInstance as AddResourceCommand).QueriedType;
  
 //проверка на ноль List, Collection, 
 if (venues != null && venues.Count != 0) 
 
 //get service
  _currUserProvider = (ICurrentUserProvider)context.HttpContext.RequestServices.GetService(typeof(ICurrentUserProvider));
  
  
  // default get/set property
    public bool isAdmin { get; set; } = false;
  
  // get name of enum property
  nameof(SupportedFileTypes.image))
  // Union
  IEnumerable<ContentResource> result = htmlContent.Union(pageContent);
   public class CalibratedDistance
    {
        [Key]
        [Column("CalibratedDistanceId")] // if it will be changed, it is necessary to change this also in sql which is in DisplayGraphHandler.cs , GetCalibrationReportsHandler class
        public long Id { get; set; }

        public Guid FromUuid { get; set; }
        public int FromMajor { get; set; }
        public int FromMinor { get; set; }

        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }

        public Guid ToUuid { get; set; }
        public int ToMajor { get; set; }
        public int ToMinor { get; set; }

        public int CalibratedPower { get; set; }
        public double Minimum { get; set; }
        public double Maximum { get; set; }
        public double Average { get; set; }
        public double AverageSquared { get; set; }

        public long Samples { get; set; }
    }
}


  public class Display
    {
        [Key]
        [Column("DisplayId")] // if it will be changed, it is necessary to change this also in sql which is in DisplayGraphHandler.cs , GetCalibrationReportsHandler class
        public int Id { get; set; }

        public DisplayType Type { get; set; }

        public int? DisplayedItemId { get; set; }
        [ForeignKey("DisplayedItemId")]
        public virtual ExhibitionItem DisplayedItem { get; set; }

        public string Name { get; set; }

        public int? VenueId { get; set; }
        [ForeignKey("VenueId")]
        public Venue Venue { get; set; }
    }
    
    
    using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ForumWeb.Models
{
    public class Beacon
    {
        [Key]
        [Column("DisplayId")]
        public int Id { get; set; }

        [ForeignKey("Id")]
        public Display Base { get; set; }

        public Guid Uuid { get; set; }
        public int Major { get; set; }
        public int Minor { get; set; }

        public Forum.Models.BackgroundContentNotificationType? BackgroundNotification { get; set; }

        public double? Radius { get; set; }
        public int? CalibratedPower { get; set; }
        public short? BatteryLevel { get; set; }
        public DateTime? LastBatteryLevelReading { get; set; }
    }
}
 
 
 
 
  IEnumerable<CalibrationReport> result = await
              (from calDist in db.CalibratedDistances
               join tobeacon in db.Beacons on new { a = calDist.ToUuid, b = calDist.ToMajor, c = calDist.ToMinor } equals new { a = tobeacon.Uuid, b = tobeacon.Major, c = tobeacon.Minor }
               where tobeacon.Base.VenueId == message.VenueId
               where now.Subtract(calDist.StartTime) < timeLimit
               select new { calDist.FromUuid, calDist.FromMajor, calDist.FromMinor, calDist.StartTime, calDist.ToMinor, calDist.Average })
               .Distinct()
               .OrderByDescending(d => d.StartTime) 
               .ThenBy(d => d.FromMinor) //  sort the collection ascending order. 
               .Select(d => new CalibrationReport { Uuid = d.FromUuid, Major = d.FromMajor, Minor = d.FromMinor, StartTime = d.StartTime }).ToListAsync();
             

             return result;
          // выбрать из displays все которых нет в displayPositions со свойством removed
          
            IQueryable<Display> query = db.Displays.Except(db.DisplayPositions.Where(x=> x.Map.Removed == false).Select(x => x.Display)).Where(display => display.Type == message.Type);