public async Task Create(ONGViewModel ongViewModel)
        {
            var ong = _mapper.Map <NonGovernamentalOrganization>(ongViewModel);

            ong.CNPJ = ongViewModel.CNPJ.RemoveSpecialCharacters();

            var responsible = ong.Responsible;

            _ongRepository.CreateResponsible(responsible);

            var address = ong.Address;
            var latlong = _googleMapsService.GetLocation(AddressToViewModel(address));

            address.Latitude  = latlong.Latitude;
            address.Longitude = latlong.Longitude;

            _ongRepository.CreateAddress(address);

            ong.SetResponsible(responsible);
            ong.SetAddress(address);

            _ongRepository.Create(ong);

            await _ongRepository.UnitOfWork.Commit();
        }
        public async Task <IActionResult> Info(ONGViewModel ongViewModel)
        {
            await _ongAppService.Update(ongViewModel);

            TempData[TempDataConstants.ShowAlert] = AlertFactory.ONGUpdated();

            return(RedirectToAction("Index"));
        }
        public async Task UpdateUserId(ONGViewModel ongViewModel, Guid userId)
        {
            var ong = await _ongRepository.GetById(ongViewModel.Id);

            ong.SetUserId(userId);

            await _ongRepository.UnitOfWork.Commit();
        }
        public async Task Update(ONGViewModel ongViewModel)
        {
            Guid ongId;

            if (ongViewModel.Id == Guid.Empty)
            {
                ongId = GetCurrentLoggedONG().Result.Id;
            }
            else
            {
                ongId = ongViewModel.Id;
            }

            var ong = await _ongRepository.GetById(ongId);

            if (!ong.Approved.HasValue)
            {
                if (ongViewModel.Approved == "Sim")
                {
                    ong.Approve();
                }
                else
                {
                    ong.Disapprove();
                }
            }
            else
            {
                var address = ong.Address;

                address.State        = ongViewModel.AddressState;
                address.City         = ongViewModel.AddressCity;
                address.ZipCode      = ongViewModel.AddressZipCode;
                address.Street       = ongViewModel.AddressStreet;
                address.Number       = ongViewModel.AddressNumber;
                address.Neighborhood = ongViewModel.AddressNeighborhood;
                address.Complement   = ongViewModel.AddressComplement;

                var latlong = _googleMapsService.GetLocation(AddressToViewModel(address));
                address.Latitude  = latlong.Latitude;
                address.Longitude = latlong.Longitude;

                var responsible = ong.Responsible;
                responsible.PhoneNumber = ongViewModel.ResponsiblePhoneNumber;
            }

            _ongRepository.Update(ong);

            await _ongRepository.UnitOfWork.Commit();
        }
Example #5
0
        public async Task <IActionResult> Upsert(Guid?id)
        {
            var ong = new ONGViewModel();

            if (!id.HasValue)
            {
                return(View(ong));
            }

            ong = await _ongAppService.Find(id.Value);

            if (ong == null)
            {
                return(NotFound());
            }

            return(View(ong));
        }
Example #6
0
        public async Task <IActionResult> Upsert(ONGViewModel ongViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(ongViewModel));
            }

            if (ongViewModel.Id == Guid.Empty)
            {
                await _ongAppService.Create(ongViewModel);
            }
            else
            {
                await _ongAppService.Update(ongViewModel);
            }

            TempData[TempDataConstants.ShowAlert] = AlertFactory.NewONGCreated();

            return(RedirectToAction("Index"));
        }