예제 #1
0
        public async Task <ScreenForReturnDto> Update(ScreenForCreationDto updateDto)
        {
            var checkByIdFromRepo = await screenDal.GetAsync(x => x.Id == updateDto.Id);

            if (checkByIdFromRepo == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound });
            }

            if (updateDto.Position.ToLower() != checkByIdFromRepo.Position.ToLower())
            {
                var subs = await subSCreenDal.GetListAsync(x => x.ScreenId == checkByIdFromRepo.Id);

                if (updateDto.Position.ToLower() == "vertical" && checkByIdFromRepo.Position.ToLower() == "horizontal")
                {
                    foreach (var item in subs)
                    {
                        if (item.Position == "Left")
                        {
                            item.Name     = checkByIdFromRepo.Name + " Üst";
                            item.Position = "Top";
                        }

                        if (item.Position == "Middle")
                        {
                            item.Name     = checkByIdFromRepo.Name + " Orta";
                            item.Position = "Middle";
                        }

                        if (item.Position == "Right")
                        {
                            item.Name     = checkByIdFromRepo.Name + " Alt";
                            item.Position = "Bottom";
                        }
                    }

                    await subSCreenDal.UpdateRange(subs);
                }

                if (updateDto.Position.ToLower() == "horizontal" && checkByIdFromRepo.Position.ToLower() == "vertical")
                {
                    foreach (var item in subs)
                    {
                        if (item.Position == "Top")
                        {
                            item.Name     = checkByIdFromRepo.Name + " Sol";
                            item.Position = "Left";
                        }
                        if (item.Position == "Middle")
                        {
                            item.Name     = checkByIdFromRepo.Name + " Orta";
                            item.Position = "Middle";
                        }
                        if (item.Position == "Bottom")
                        {
                            item.Name     = checkByIdFromRepo.Name + " Sağ";
                            item.Position = "Right";
                        }
                    }
                    await subSCreenDal.UpdateRange(subs);
                }
            }

            var mapForUpdate = mapper.Map(updateDto, checkByIdFromRepo);
            await screenDal.Update(mapForUpdate);

            return(mapper.Map <Screen, ScreenForReturnDto>(mapForUpdate));
        }