示例#1
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;
                }
            }
        }
示例#2
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;
         }
     }
 }
示例#3
0
 public async Task<IActionResult> UpdateDive(DiveViewModel dive)
 {
     if (User.Identity.IsAuthenticated)
     {
         if (ModelState.IsValid)
         {
             var user = await _userManager.FindByEmailAsync(User.Identity.Name);
             if (dive.DiveID == 0)
             {
                 var result = _diveManager.UpdateDive(dive, user);
             }
             return new HttpOkResult();
         }
         this.Response.StatusCode = 400;
         return Json(ModelState.Values.Where(v => v.ValidationState == Microsoft.AspNet.Mvc.ModelBinding.ModelValidationState.Invalid)
                                      .Select(m => new
                                      {
                                          error = m.Errors.First().ErrorMessage.ToString()
                                      }));
     }
     return new HttpUnauthorizedResult();
 }