public async Task <bool> Add(EventInputModel eventInputModel)
        {
            List <EventPhoto> eventPhotos = new List <EventPhoto>();

            if (eventInputModel.Photos != null)
            {
                foreach (var i in eventInputModel.Photos)
                {
                    eventPhotos.Add(new EventPhoto(new Photo(i)));
                }
            }

            List <EventParticipants> eventParticipants = new List <EventParticipants>();

            eventParticipants.Add(new EventParticipants(eventInputModel.personIdCadastro, true));

            var eventId = await _eventRepository.Add(new Event(eventInputModel.Name, eventInputModel.StartDate, eventInputModel.EndDate, eventInputModel.PageProfileLink, eventInputModel.About, eventPhotos, eventParticipants));

            await _addressRepository.Add(new Address(eventInputModel.Address.Longitude,
                                                     eventInputModel.Address.Latitude,
                                                     eventInputModel.Address.Street,
                                                     eventInputModel.Address.Neighborhood,
                                                     eventInputModel.Address.Province,
                                                     eventInputModel.Address.Zip,
                                                     eventInputModel.Address.City,
                                                     eventInputModel.Address.Country,
                                                     eventInputModel.Address.Number,
                                                     personId : null,
                                                     eventId : eventId));

            return(eventId > 0);
        }
        public async Task <int> AddAddressAsync(Address entity, string latitude, string longitude)
        {
            try
            {
                entity = AddressCoordinatesTransformer.ConvertCoordinates(entity, latitude, longitude);
                _logger.Information("Address service Layer access in progress...");
                var dbAddress = await _addressRepository.GetSingleAsNoTrackingAsync(entity.AddressStr);

                if (dbAddress != null)
                {
                    return(-1);
                }
                if (entity.OpeningHours == null)
                {
                    entity.OpeningHours = "none";
                }
                _addressRepository.Add(entity);
                await _addressRepository.SaveChangesAsync();

                _logger.Information($"Address table has been modified! Address:\n Id: {entity.Id}\n Address string: {entity.AddressStr}\n has been inserted.");
                return(0);
            }
            catch (Exception e)
            {
                _logger.Error($"Address service layer error occured! Error message: {e.Message}");
                return(-2);
            }
        }
Beispiel #3
0
        public ActionResult SaveEmployee(PersonAddressViewModel personAddressViewModel)
        {
            if (ModelState.IsValid)
            {
                var Person  = new Person();
                var Address = new Address();

                Person.FirstName = personAddressViewModel.FirstName;
                Person.LastName  = personAddressViewModel.LastName;
                Person.Email     = personAddressViewModel.Email;
                Address.Address1 = personAddressViewModel.Address1;
                Address.Address2 = personAddressViewModel.Address2;
                Address.City     = personAddressViewModel.City;
                Address.State    = personAddressViewModel.State;
                Address.ZipCode  = personAddressViewModel.ZipCode;

                _personRepository.Add(Person);
                _personRepository.Save();

                Address.AddressId = Person.PersonId;
                _addressRepository.Add(Address);
                _addressRepository.Save();
                return(RedirectToAction("EmployeeDetails"));
            }
            else
            {
                return(View("AddAddress", personAddressViewModel));
            }
        }
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]                                  // if something unexpectedly went wrong with the database or http request/response
        public async Task <ActionResult <Furs2Feathers.Domain.Models.Address> > PostAddress(Furs2Feathers.Domain.Models.Address address)
        {
            addressRepo.Add(address);
            await addressRepo.SaveChangesAsync();

            return(CreatedAtAction("GetAddress", new { id = address.AddressId }, address));
        }
Beispiel #5
0
        public NewAddressResponse RegisterAddress(NewAddressRequest newAddressRequest)
        {
            var newAddress = new Address
            {
                UserId      = newAddressRequest.UserId,
                Name        = newAddressRequest.Name,
                Type        = newAddressRequest.Type,
                Description = newAddressRequest.Description,
                City        = newAddressRequest.City,
                State       = newAddressRequest.State,
                Country     = newAddressRequest.Country,
                ZipCode     = newAddressRequest.ZipCode
            };

            var addedAddress = _AddressRepository.Add(newAddress);

            _AddressRepository.SaveChanges();

            return(new NewAddressResponse
            {
                Id = addedAddress.Id,
                UserId = addedAddress.UserId,
                Name = addedAddress.Name,
                Type = addedAddress.Type,
                Description = addedAddress.Description,
                City = addedAddress.City,
                State = addedAddress.State,
                Country = addedAddress.Country,
                ZipCode = addedAddress.ZipCode
            });
        }
        public override void Add(User entity)
        {
            using (var dbContextTransaction = dataContext.Database.BeginTransaction())
            {
                try
                {
                    if (entity.Address != null)
                    {
                        addressRepository.Add(entity.Address);
                        addressRepository.Save();
                    }
                    base.Add(entity);
                    base.Save();

                    Cart cart = new Cart();
                    cart.CustomerID = entity.UserID;
                    cartRepository.Add(cart);
                    cartRepository.Save();

                    WishList wishList = new WishList();
                    wishList.CustomerID = entity.UserID;
                    wishListRepository.Add(wishList);
                    wishListRepository.Save();

                    dbContextTransaction.Commit();
                }
                catch (Exception e)
                {
                    dbContextTransaction.Rollback();
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// This function manage data from service to repository pattern.
        /// </summary>
        /// <param name="item">Inserted object</param>
        /// <returns>Pre-mapped object</returns>
        public Address Create(AddressDTO item)
        {
            _repository.Add(item);
            _repository.Save();

            return(_mapper.Map <Address>(item));
        }
        public async Task <bool> Add(HomelessInputModel homelessInputModel)
        {
            List <PersonPhoto> personPhotos = new List <PersonPhoto>();

            if (homelessInputModel.Photos != null)
            {
                foreach (var i in homelessInputModel.Photos)
                {
                    personPhotos.Add(new PersonPhoto(new Photo(i)));
                }
            }

            var homelessId = await _homelessRepository.Add(new Homeless(homelessInputModel.Needs, homelessInputModel.About, homelessInputModel.CounterNotFound, new Person(homelessInputModel.Name, "", personPhotos), homelessInputModel.personIdCadastro));

            var homeless = await _homelessRepository.Get(homelessId);

            await _addressRepository.Add(new Address(homelessInputModel.Address.Longitude,
                                                     homelessInputModel.Address.Latitude,
                                                     homelessInputModel.Address.Street,
                                                     homelessInputModel.Address.Neighborhood,
                                                     homelessInputModel.Address.Province,
                                                     homelessInputModel.Address.Zip,
                                                     homelessInputModel.Address.City,
                                                     homelessInputModel.Address.Country,
                                                     homelessInputModel.Address.Number,
                                                     personId : homeless.PersonId,
                                                     eventId : null));

            return(homelessId > 0);
        }
        public IActionResult CreateAddress(int id, [FromBody] AddressViewModel address, [FromBody] CustomerViewModel customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Customer _customerDb = _customerRepository.GetSingle(id);
            Address  _newAddress;

            if (_customerDb == null)
            {
                return(NotFound());
            }
            else
            {
                _newAddress = new Address
                {
                    Address1   = address.Address1,
                    Address2   = address.Address2,
                    City       = address.City,
                    ZipCode    = address.ZipCode,
                    State      = address.State,
                    CustomerId = id
                };
            }
            _addressRepository.Add(_newAddress);
            _addressRepository.Commit();

            address = Mapper.Map <Address, AddressViewModel>(_newAddress);

            CreatedAtRouteResult result = CreatedAtRoute("GetAddress", new { controller = "Address", id = address.Id }, address);

            return(result);
        }
Beispiel #10
0
        public async Task <int> FirstVisit_Post(FirstVisitVM firstVisit)
        {
            firstVisit.Visit.VisitDate = firstVisit.Visit.VisitDate + firstVisit.Visit.TimeOfVisit;
            var visits = _visitRepository.GetForDateTime(firstVisit.Visit.VisitDate);

            if (firstVisit.Visit.DentistId == 0)
            {
                if (visits.Any())
                {
                    if (visits.Select(v => v.PatientId).Contains(firstVisit.Visit.PatientId))
                    {
                        // return 1;
                    }
                    var dentists = _dentistRepository.GetAll().Select(d => d.Id).ToList();
                    foreach (var v in visits)
                    {
                        if (dentists.Contains(v.DentistId))
                        {
                            dentists.Remove(v.DentistId);
                        }
                    }
                    if (dentists.Any())
                    {
                        firstVisit.Visit.DentistId = dentists.First();
                    }
                }
                else
                {
                    firstVisit.Visit.DentistId = _dentistRepository.GetAll().Select(d => d.Id).First();
                }
            }
            var patient = _mapper.Map <Patient>(firstVisit.Patient);
            await _patientRepository.Add(patient);

            var address = _mapper.Map <Address>(firstVisit.Patient.Address);

            address.PatientId = patient.Id;
            await _addressRepository.Add(address);

            var visit = _mapper.Map <Visit>(firstVisit.Visit);

            visit.PatientId = patient.Id;
            await _visitRepository.Add(visit);

            return(0);
        }
Beispiel #11
0
        public IEnumerable <AddressDTO> CreateNewAddress(AddressDTO addressDTO)
        {
            Address address = new Address(addressDTO.AddressCode, addressDTO.AddressStreet, addressDTO.District, addressDTO.Locality, addressDTO.FederalUnit);

            _addressRepository.Add(address);
            _addressRepository.SaveChanges();

            return(_mapper.Map <IEnumerable <AddressDTO> >(_addressRepository.GetLast10Addresses()));
        }
Beispiel #12
0
        public Address Create(int suburbId, string street1, string street2 = "")
        {
            var address = new Address {
                SuburbId = suburbId, Street1 = street1, Street2 = street2
            };

            _repoAddress.Add(address);
            return(address);
        }
Beispiel #13
0
 public IActionResult Create([FromBody] Address item)
 {
     passport = CommonMethod.GetPassport(Request);
     if (item == null)
     {
         return(BadRequest());
     }
     return(new ObjectResult(service.Add(passport, item)));
 }
Beispiel #14
0
        public async Task <Address> Add(Address address)
        {
            if (!Valid(address))
            {
                throw new InvalidUserObject("Address");
            }

            return(await _addressRepository.Add(address));
        }
Beispiel #15
0
        public async Task Add(Address address)
        {
            if (!IsValid(address))
            {
                return;
            }

            await _addressRepository.Add(address);
        }
        public IActionResult Create([Bind("Id,Street,Number")] Address address)
        {
            if (ModelState.IsValid)
            {
                _addressRepo.Add(address);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(address));
        }
Beispiel #17
0
        public async Task <bool> Update(OngInputModel ongInputModel)
        {
            List <PersonPhoto> personPhotos = new List <PersonPhoto>();

            if (ongInputModel.Photos != null)
            {
                foreach (var i in ongInputModel?.Photos)
                {
                    personPhotos.Add(new PersonPhoto(new Photo(i)));
                }
            }

            var ong = await _ongRepository.GetByPersonId(ongInputModel.personId);

            ong.Update(ongInputModel.OpeningTime, ongInputModel.ClosingTime, ongInputModel.PageProfileLink ?? "", ongInputModel.About);
            ong.Person.Update(ongInputModel.Name, ongInputModel.Phone);
            ong.Person.PersonPhotos = personPhotos;

            var ongId = await _ongRepository.Update(ong);

            var address = await _addressRepository.GetByPersonId(ongInputModel.personId);

            if (address != null)
            {
                address.Update(ongInputModel.Address.Longitude,
                               ongInputModel.Address.Latitude,
                               ongInputModel.Address.Street,
                               ongInputModel.Address.Neighborhood,
                               ongInputModel.Address.Province,
                               ongInputModel.Address.Zip,
                               ongInputModel.Address.City,
                               ongInputModel.Address.Country,
                               ongInputModel.Address.Number,
                               personId: ong.Person.Id,
                               eventId: null);

                await _addressRepository.Update(address);
            }
            else
            {
                await _addressRepository.Add(new Address(ongInputModel.Address.Longitude,
                                                         ongInputModel.Address.Latitude,
                                                         ongInputModel.Address.Street,
                                                         ongInputModel.Address.Neighborhood,
                                                         ongInputModel.Address.Province,
                                                         ongInputModel.Address.Zip,
                                                         ongInputModel.Address.City,
                                                         ongInputModel.Address.Country,
                                                         ongInputModel.Address.Number,
                                                         personId : ong.Person.Id,
                                                         eventId : null));
            }

            return(ongId > 0);
        }
Beispiel #18
0
        public ActionResult AddressInsert(AddressViewModel address)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            var addressModel = new Address()
            {
                Description = address.Description,
                CityId      = address.CityId,
                StateId     = address.StateId,
                CountryId   = address.CountryId,
                UserId      = User.Identity.GetUserId <int>()
            };

            _addressRepository.Add(addressModel);
            _addressRepository.Complete();

            return(Json(""));
        }
        public async Task <ActionResult> Add(ShoppingAddress address)
        {
            if (ModelState.IsValid)
            {
                addressRepository.Add(address);
                await addressRepository.Save();

                return(RedirectToAction("Confirm", "Order", new { addressId = address.ShoppingAddressID }));
            }

            return(View(address));
        }
Beispiel #20
0
        /// <summary>
        /// Create address for registered account user
        /// </summary>
        /// <param name="address">The address</param>
        /// <returns>Return address</returns>
        public Address AddAddress(Address address)
        {
            if (address == null)
            {
                throw new Exception("Address required to create account user");
            }

            _addressRepository.Add(address);
            _addressRepository.Commit();

            return(_addressRepository.GetInsertedAddress());
        }
Beispiel #21
0
        private Address addAddress(string fl, string t, string pc, string c)
        {
            Address addr = new Address
            {
                FirstLine = fl,
                Town      = t,
                PostCode  = pc,
                Country   = c
            };

            return(addrRepository.Add(addr));
        }
Beispiel #22
0
        public async Task <IActionResult> Create(Address address)
        {
            if (!ModelState.IsValid)
            {
                return(View(address));
            }

            _addressRepo.Add(address);
            await _uow.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <int> AddRoasterAsync(Roaster roaster,
                                                string tags,
                                                Address address,
                                                string latitude,
                                                string longitude,
                                                IFormFile picture)
        {
            try
            {
                _logger.Information("Roaster admin service layer access in progress...");

                var roasterByName = await _roasterRepository.GetRoasterByNameNonTrackableAsync(roaster.Name);

                if (roasterByName != null)
                {
                    return(-1);
                }

                //Get and process tags string into tag entities
                var _localTags = await RoasterAdminServiceBuilder.BuildTagsListAsync(tags,
                                                                                     _tagRepository);

                //process address entity
                var _address = Address.New(address.AddressStr,
                                           address.OpeningHours,
                                           address.Latitude,
                                           address.Longitude);
                address = AddressCoordinatesTransformer.ConvertCoordinates(address, latitude, longitude);
                roaster.OfficeAddress = _address;
                _addressReposiotry.Add(_address);
                //add roasterTags  notes
                RoasterTagsPairsBuilder.BuildRoasterTags(_localTags,
                                                         roaster.Id,
                                                         _roasterTagRepository);

                var pictureBytes = BytePictureBuilder.GetBytePicture(picture);
                BytePictureBuilder.BindPicture(roaster.Id, pictureBytes, _pictureRepository);

                roaster = RoasterAdminServiceBuilder.AddRoasterNullPlugs(roaster);

                _roasterRepository.Add(roaster);
                await _roasterRepository.SaveChangesAsync();

                _logger.Information($"Roaster, Tags, RoasterTags, Addresses tables have been modified. Inserted roaster:\n Id: {roaster.Id}\n Roaster name: {roaster.Name}");
                return(0);
            }
            catch (Exception e)
            {
                _logger.Error($"Roaster admin service layer error occured! Error text message: {e.Message}");
                return(-2);
            }
        }
Beispiel #24
0
        public CommandResult Handle(CreateAddressCommand command)
        {
            var result = command.Validate();

            if (result.IsValid)
            {
                var address = new Address(Guid.NewGuid(), command.Street, command.City, command.State, command.Country, command.ZipCode, command.Type);
                _repository.Add(address);
                result.Value = address;
            }

            return(result);
        }
        public async Task <int> CreateAddress(AddressVm address, int employeeId)
        {
            var entityAddress = mapper.Map <Address>(address);

            entityAddress.EmployeeId = employeeId;

            addressRepository.Add(entityAddress);
            if (await addressRepository.SaveAll())
            {
                return(entityAddress.Id);
            }

            return(-1);
        }
        public async Task <IActionResult> Add(Address address)
        {
            if (ModelState.IsValid)
            {
                if (!await addressRepository.Add(address))
                {
                    return(BadRequest("Could not save"));
                }

                return(RedirectToAction("Index"));
            }

            return(View(address));
        }
        public async ValueTask <long> CreateAsync(Company organization, CancellationToken cancellationToken = default)
        {
            // fix. SqlException: Cannot insert explicit value for identity column in table 'Address' when IDENTITY_INSERT is set to OFF.
            //  * assign to 0 otherwise ValueGeneratedOnAdd() is not working
            organization.Id             = 0L;
            organization.MainAddressId  = 0L;
            organization.MainAddress.Id = 0L;
            _addressRepository.Add(organization.MainAddress);
            await _addressRepository.CommitAsync(cancellationToken);

            _companyRepository.Add(organization);
            await _companyRepository.CommitAsync(cancellationToken);

            return(organization.Id);
        }
Beispiel #28
0
        public IActionResult Create([FromBody] Address item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _addressRepository.Add(item);
            return(CreatedAtRoute("GetAddress", new { id = item.Id, cid = item.CustomerId }, item));
        }
Beispiel #29
0
        public IActionResult AddNewAddress(AddressViewModel model)
        {
            if (!ModelState.IsValid)
            {
                FillModel(model);
                return(View(model));
            }

            var address = _mapper.Map <Address>(model);

            _addressRepository.Add(address);
            _addressRepository.Save();

            return(RedirectToAction(model.Next ? "AddNewAddress" : "AddressManagement"));
        }
Beispiel #30
0
 public void SaveUser(UserDTO userDTO, AddressDTO addressDTO)
 {
     try
     {
         // Is doesn't matter if you use _userRepository or _addressRepository,
         // because this classes use the same UnitOfWork.
         _userRepository.UnitOfWork.BeginTransaction();
         _userRepository.Add(ConvertToUser(userDTO));
         _addressRepository.Add(ConvertToAddress(addressDTO));
         _userRepository.UnitOfWork.SaveCahnges();
         _userRepository.UnitOfWork.Commit();
     }
     catch (Exception)
     {
         _userRepository.UnitOfWork.Rollback();
     }
 }