public async Task <bool> UpdateLRD(int id, LrddatasDto data) { Lrddatas lrdData = _mapper.Map <LrddatasDto, Lrddatas>(data); bool result = _repo.LRDRepository.Update(id, lrdData); await _repo.SaveAsync(); return(result); }
public async Task <LrddatasDto> Get(int id) { Lrddatas data = await _entities.Lrddatas .Include(x => x.Lrdcategories).Include(x => x.LrdattributesLookups) .Where(x => x.LrddataId == id).FirstOrDefaultAsync(); LrddatasDto result = _mapper.Map <Lrddatas, LrddatasDto>(data); return(result); }
public async Task <LrddatasDto> DeleteLRD(int id) { LrddatasDto res = new LrddatasDto(); bool result = false; var lrd = await _entities.LrdattributesLookups.Where(x => x.LrddataLrddataId == id).FirstOrDefaultAsync(); if (lrd != null) { result = _repo.LRDattributesLookupsRepository.Delete(lrd.Id); await _repo.SaveAsync(); } Lrddatas res2 = await _repo.LRDRepository.Get(id); result = _repo.LRDRepository.Delete(id); await _repo.SaveAsync(); res = _mapper.Map <Lrddatas, LrddatasDto>(res2); return(res); }
public async Task <LrddatasDto> CreateLRD(LrddatasDto data) { if (data.LrddataId != 0) { Lrddatas lrdData = _mapper.Map <LrddatasDto, Lrddatas>(data); bool result2 = _repo.LRDRepository.Update(data.LrddataId, lrdData); await _repo.SaveAsync(); return(data); } else { Lrddatas lrdDatas = new Lrddatas(); lrdDatas.Title = data.Title; lrdDatas.VideoUrl = data.VideoUrl; lrdDatas.ContentLocation = data.ContentLocation; lrdDatas.Text = data.Text; lrdDatas.Lrdtype = data.Lrdtype; var lrddataID = _entities.Lrddatas.Add(lrdDatas); await _entities.SaveChangesAsync(); if (data.LrdattributesLookups != null) { var lrdAttributeLookups = data.LrdattributesLookups.ToList(); for (int i = 0; i < lrdAttributeLookups.Count; i++) { LrdattributesLookups lrdAttribute = new LrdattributesLookups(); lrdAttribute.LrdattributesId = lrdAttributeLookups[i].LrdattributesId; lrdAttribute.LrdcategoryId = lrdAttributeLookups[i].LrdcategoryId; lrdAttribute.LrddataLrddataId = lrddataID.Entity.LrddataId; _entities.LrdattributesLookups.Add(lrdAttribute); } var lrdId = await _entities.SaveChangesAsync(); } LrddatasDto result = _mapper.Map <Lrddatas, LrddatasDto>(lrdDatas); return(result); } }