public async Task<LiftName> CreateAsync(LiftName liftName)
 {
     try
     {
         await _context.LiftNames.AddAsync(liftName);
     }
     catch (Exception ex)
     {
         // Logging
         return liftName;
     }
     return liftName;
 }
        public async Task <LiftViewModel> UpdateAsync(LiftViewModel lift, string uid)
        {
            /*
             * Update lift and call GetAll to retrieve the updated lifts
             */
            //var vm = new LiftViewModel();
            Lift     l           = _liftRepository.Get(lift.Lift.Id, uid);
            LiftName liftName    = _liftNameRepository.GetByName(lift.LiftName);
            LiftType liftType    = _liftTypeRepository.GetByName(lift.LiftType);
            var      updatedLift = await _liftRepository.UpdateAsync(l, uid);

            return(LiftMapper.MapLiftToViewModel(updatedLift, uid));//, liftName, liftType, uid);
        }
        public async Task <LiftViewModel> CreateAsync(LiftViewModel viewModel, string uid)
        {
            /*
             * Create lift and call GetAll to retrieve the updated lifts
             * - Add DaysService call to change Id (int) to String (day)
             */
            LiftName liftName = _liftNameRepository.GetByName(viewModel.LiftName);
            LiftType liftType = _liftTypeRepository.GetByName(viewModel.LiftType);
            Lift     lift     = LiftMapper.MapViewModelToLift(viewModel, uid, liftName, liftType);

            lift = await _liftRepository.CreateAsync(lift, uid);

            return(LiftMapper.MapLiftToViewModel(lift, uid));//, liftName, liftType, uid);
        }
        public LiftViewModel Get(string id, string uid)
        {
            Lift     lift     = _liftRepository.Get(id, uid);
            LiftName liftName = _liftNameRepository.Get(lift.LiftName.Id);
            LiftType liftType = _liftTypeRepository.Get(lift.LiftType.Id);

            LiftViewModel viewModel = LiftMapper.MapLiftToViewModel(lift, uid);//,

            //liftName,
            //liftType,
            //uid);

            return(viewModel);
        }
        public async Task<LiftName> UpdateAsync(LiftName liftName)
        {

            try
            {
                _context.Entry(liftName).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                // logging
                return liftName;
            }
            return liftName;

        }
Example #6
0
 public static Lift MapViewModelToLift(LiftViewModel viewModel, string uid, LiftName liftName, LiftType liftType)
 {
     return(new Lift()
     {
         Id = Guid.NewGuid().ToString(),
         MaxLift = viewModel.MaxLift,
         IsMainLift = viewModel.IsMainLift,
         Date = viewModel.Date,
         UserId = uid,
         LiftName = new LiftName()
         {
             Id = liftName.Id
         },
         LiftType = new LiftType()
         {
             Id = liftType.Id
         }
     });
 }
 public async Task <LiftName> UpdateAsync(LiftName liftName)
 {
     return(await _liftNameRepository.UpdateAsync(liftName));
 }