Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Delete([FromRoute] int id)
        {
            LrddatasDto result = await _lrdServices.DeleteLRD(id);

            if (result != null)
            {
                return(Ok(result));
            }
            return(NotFound());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] LrddatasDto data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _lrdServices.CreateLRD(data);

            if (result != null)
            {
                return(Ok(result));
            }
            return(BadRequest());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] LrddatasDto data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != data.LrddataId)
            {
                return(BadRequest());
            }
            var result = await _lrdServices.UpdateLRD(id, data);

            if (result == true)
            {
                return(Ok(Properties.Resources.ResourceManager.GetString("SuccUpdateMessage")));
            }
            return(BadRequest());
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
            }
        }