Esempio n. 1
0
        public IEnumerable<DiveGeoViewModel> GetDivesGeoData(User user)
        {
            using (EntityContext _context = new EntityContext())
            {
                try
                {
                    var result = _context.Dives.Where(d => d.User.Id == user.Id && d.Status)
                                               .Include(d => d.Photos)
                                               .OrderBy(d => d.DiveDate)
                                               .ToArray()
                                               .Select((dive, i) => new DiveGeoViewModel()
                                               {
                                                   DiveId = dive.DiveID,
                                                   DiveNumber = (i + 1),
                                                   DiveDate = dive.DiveDate.ToShortDateString(),
                                                   DiveComment = dive.Comments,
                                                   Depth = dive.MaxDepth.ToString(),
                                                   DiveTime = dive.TotalMinutes.ToString(),
                                                   Location = dive.Location,
                                                   CoordinateX = dive.DiveX.ToString(),
                                                   CoordinateY = dive.DiveY.ToString(),
                                                   HasPhotos = dive.Photos.Any()
                                               });
                    return result;
                }
                catch (Exception ex)
                {
                    throw ex;

                }
            }
        }
Esempio n. 2
0
 public bool DeleteDive(long diveId, User user)
 {
     using (EntityContext _context = new EntityContext())
     {
         var dive = _context.Dives.Where(d => d.User.Id == user.Id && d.DiveID == diveId).First();
         dive.Status = false;
         return _context.SaveChanges() > 0;
     }
 }
Esempio n. 3
0
        public long AddPhoto(long diveId, User user, byte[] photo, string name)
        {
            using (EntityContext _context = new EntityContext())
            {
                var dive = _context.Dives.Where(d => d.User.Id == user.Id && d.DiveID == diveId).First();
                var photoDesc = new Photos()
                {
                    DiveID = diveId,
                    Status = true,
                    PhotoDate = DateTime.Now,
                    PhotoName = name,
                    PhotoVal = photo
                };

                _context.Photos.Add(photoDesc);
                _context.SaveChanges();

                return photoDesc.PhotoID;
            }
        }
Esempio n. 4
0
 public bool UpdateDive(DiveViewModel dive, User user)
 {
     using (EntityContext _context = new EntityContext())
     {
         try
         {
             var updDive = _context.Dives.Where(d => d.User.Id == user.Id && d.DiveID == dive.DiveID).First();
             updDive.Country = dive.CountryId;
             updDive.Countries = _context.DicCountries.Where(c => c.CountryKod == dive.CountryId).First();
             updDive.AirTemperature = dive.AirTemperature;
             updDive.Comments = dive.Comments;
             updDive.DiveDate = dive.DiveDate;
             updDive.DiveTime = dive.DiveTime;
             updDive.FiveMetersMinutes = dive.FiveMetersMinutes;
             updDive.DiveX = dive.Latitude;
             updDive.Location = dive.Location;
             updDive.DiveY = dive.Longitude;
             updDive.MaxDepth = dive.MaxDepth;
             updDive.SuitType = dive.SuitType;
             updDive.Tank = dive.Tank;
             updDive.TankEnd = dive.TankEnd;
             updDive.TankStart = dive.TankStart;
             updDive.TotalMinutes = dive.TotalMinutes;
             updDive.Visibility = dive.Visibility;
             updDive.WaterTemperature = dive.WaterTemperature;
             updDive.Weight = dive.Weight;
             updDive.WeightIsOk = dive.WeightIsOk;
             updDive.UpdDate = DateTime.Now;
             return _context.SaveChanges() > 0;
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Esempio n. 5
0
        public bool SaveDive(DiveViewModel dive, User user)
        {
            using (EntityContext _context = new EntityContext())
            {
                try
                {
                    var newDive = new Dive()
                    {
                        User = user,
                        Country = dive.CountryId,
                        Countries = _context.DicCountries.Where(c => c.CountryKod == dive.CountryId).First(),
                        AirTemperature = dive.AirTemperature,
                        Comments = dive.Comments,
                        DiveDate = dive.DiveDate,
                        DiveTime = dive.DiveTime,
                        FiveMetersMinutes = dive.FiveMetersMinutes,
                        DiveX = dive.Latitude,
                        Location = dive.Location,
                        DiveY = dive.Longitude,
                        MaxDepth = dive.MaxDepth,
                        SuitType = dive.SuitType,
                        Tank = dive.Tank,
                        TankEnd = dive.TankEnd,
                        TankStart = dive.TankStart,
                        TotalMinutes = dive.TotalMinutes,
                        Visibility = dive.Visibility,
                        WaterTemperature = dive.WaterTemperature,
                        Weight = dive.Weight,
                        WeightIsOk = dive.WeightIsOk,
                        UpdDate = DateTime.Now,
                        Status = true
                    };
                    _context.Dives.Add(newDive);

                    return _context.SaveChanges() > 0;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 6
0
        public PassportViewModel GetUserPassport(User user)
        {
            using (EntityContext _context = new EntityContext())
            {
                var model = new PassportViewModel();
                var dives = _context.Dives.Where(d => d.User.Id == user.Id && d.Status)
                                          .Include(d => d.Countries)
                                          .Include(d => d.Photos)
                                          .ToArray();
                model.Email = user.Email;
                model.Fio = string.Format("{0} {1}", user.FirstName, user.LastName);
                if (string.IsNullOrWhiteSpace(model.Fio)) model.Fio = unknownUser;
                if (user.Birth.HasValue)
                {
                    DateTime today = DateTime.Today;
                    int age = today.Year - user.Birth.Value.Year;
                    if (user.Birth.Value > today.AddYears(-age)) age--;
                    model.Age = age;
                }
                var country = (from c in _context.DicCountries where c.CountryKod == user.DicCountryId select c).First();
                model.Country = country.ValueEU;
                model.CountryId = country.CountryKod;
                model.DivesCount = dives.Count();
                model.MaxDepth = dives.Any(d => d.MaxDepth != null) ? dives.Where(d => d.MaxDepth != null).Select(d => d.MaxDepth.Value).Max() : 0;
                model.SumDiveMinutes = dives.Where(d => d.TotalMinutes != null).Select(d => (int)d.TotalMinutes).Sum();
                model.diveCountries = dives.Where(d => d.Countries != null)
                                           .GroupBy(d => d.Countries.CountryKod)
                                           .Select(c => new GroupedCountryViewModel
                                           {
                                               Count = c.Count(),
                                               Code = c.First().Countries.CountryKod,
                                               Name = c.First().Countries.ValueEU
                                           }).ToArray();

                model.Dives = dives.OrderBy(d => d.DiveDate)
                                   .Select(d => new DiveViewModel
                                   {
                                       DiveID = d.DiveID,
                                       CountryId = d.Country,
                                       AirTemperature = d.AirTemperature,
                                       Comments = d.Comments,
                                       DiveDate = d.DiveDate,
                                       DiveTime = d.DiveTime,
                                       FiveMetersMinutes = d.FiveMetersMinutes,
                                       Latitude = d.DiveX,
                                       Location = d.Location,
                                       Longitude = d.DiveY,
                                       MaxDepth = d.MaxDepth,
                                       SuitType = d.SuitType,
                                       Tank = d.Tank,
                                       TankEnd = d.TankEnd,
                                       TankStart = d.TankStart,
                                       TotalMinutes = d.TotalMinutes,
                                       Visibility = d.Visibility,
                                       WaterTemperature = d.WaterTemperature,
                                       Weight = d.Weight,
                                       WeightIsOk = d.WeightIsOk,
                                       Photos = d.Photos.Select(p => new PhotoViewModel
                                       {
                                           PhotoId = (int)p.PhotoID,
                                           Date = p.PhotoDate,
                                           Comment = p.PhotoComment
                                       }).ToArray()
                                   }).ToArray();

                model.Certs = _context.Certs.Where(cert => cert.User.Id == user.Id)
                                            .Select(c => new CertViewModel
                                            {
                                                CertID = c.DicCert.CertID,
                                                CertName = c.DicCert.CertName,
                                                CertNumber = c.CertNumber,
                                                DateArchieve = c.DateArchieve,
                                                Description = c.DicCert.Description,
                                                IsGeneral = c.DicCert.IsGeneral,
                                                Issuer = c.Issuer,
                                                Level = c.DicCert.Level,
                                                UserID = c.User.Id
                                            })
                                            .ToArray();

                return model;
            }
        }