示例#1
0
        public void Add(ILocation location)
        {
            try
            {
                var headquaters = new BusinessHeadquaters
                {
                    Id   = location.Id,
                    City = location.City
                };

                Lock();

                _locationRepository.Add(location);
                _businessRepository.AddHeadquaters(headquaters, location.BusinessId);
            }
            catch (Exception)
            {
                //TODO: Rollback logic
                throw new Exception("Failed to perform atomic action - " + Desc);
            }
            finally
            {
                Unlock();
            }
        }
        public Task Handle(LocationCreatedEvent @event)
        {
            Console.WriteLine("Handling LocationCreatedEvent.");
            // save to ReadDB
            Location location = new Location
                                (
                @event.Id,
                @event.Name,
                @event.Description,
                @event.SiteId
                                );

            try
            {
                _locationRepository.Add(location);
                _locationRepository.SaveChanges();
                Console.WriteLine("LocationCreatedEvent handled.");
                return(Task.CompletedTask);
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.InnerException.Message);
                throw e;
            }
        }
示例#3
0
        public async Task <IActionResult> CreateLocation(LocationDTO locationDTO)
        {
            var location = _mapper.Map <LocationDTO, Location>(locationDTO);
            await _locationRepository.Add(location);

            return(CreatedAtAction(nameof(GetLocation), new { id = location.LocationId }, location));
        }
示例#4
0
        public void Add(IBusiness business, ILocation location, IUserBusiness userBusiness, IGroup group)
        {
            try
            {
                Lock();

                _businessRepository.Add(business);
                _locationRepository.Add(location);
                _groupRepository.Add(group);

                foreach (var email in business.Members)
                {
                    var userGroup = new UserGroup
                    {
                        Id   = group.Id,
                        Name = group.Name,
                        Role = GroupRoles.Admin
                    };

                    _userRepository.AddBusinessWithEmail(userBusiness, email);
                    _userRepository.AddGroupWithEmail(userGroup, email);
                }
            }
            catch (Exception)
            {
                //TODO: Rollback logic
                throw new Exception("Failed to perform atomic action - " + Desc);
            }
            finally
            {
                Unlock();
            }
        }
示例#5
0
        public string Add(Location location)
        {
            string ret;

            try
            {
                if (location.movie.active == true && location.movie.amount > 0)
                {
                    location.locationDate       = DateTime.Now;
                    location.locationDevolution = location.locationDate.AddDays(3);
                    _locationRepository.Add(location);
                    location.movie.amount = location.movie.amount - 1;
                    _locationRepository.Commit();

                    ret = "Locação feita com sucesso, com devolução marcada para : " + location.locationDevolution;
                }
                else
                {
                    ret = "Filme indisponível";
                }
                return(ret);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Erro ao adcionar Locação");
                throw;
            }
        }
        public long Add(Location obj)
        {
            if (IsDuplicate(obj.Description, obj.Id, obj.CustomerId) == false)
            {
                return(_locationRepository.Add(obj));
            }
            else
            {
                Expression <Func <Location, bool> > res = x => x.Description == obj.Description && x.CustomerId == obj.CustomerId && x.IsActive == false;
                var model = _locationRepository.Get(res);

                if (model != null)
                {
                    obj.Id       = model.Id;
                    obj.IsActive = true;

                    _locationRepository.Detach(model);

                    _locationRepository.Update(obj);
                    return(obj.Id);
                }
                else
                {
                    return(0);
                }
            }
        }
示例#7
0
 public void AddLocation(string city, string country, string address, int orchestraid)
 {
     locationRepository.Add(new Location()
     {
         City = city, Country = country, Address = address, OrchestraId = orchestraid
     });
 }
示例#8
0
        public bool Save(List <Location> reasons, string state = "")
        {
            try
            {
                if (!string.IsNullOrEmpty(state) && state == "Save")
                {
                    reasons.ForEach(x => reasonRepository.Add(x));
                }
                else if (!string.IsNullOrEmpty(state) && state == "Update")
                {
                    reasons.ForEach(x => reasonRepository.Update(x));
                }
            }
            catch (DbEntityValidationException e)
            {
                string exceptionMessage = string.Empty;

                foreach (var eve in e.EntityValidationErrors)
                {
                    exceptionMessage = string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        exceptionMessage += string.Format("\n\n- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw new Exception(exceptionMessage);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(true);
        }
        public async Task <ActionResult <Location> > PostLocation(Location location)
        {
            locationRepo.Add(location);
            await locationRepo.SaveChangesAsync();

            return(CreatedAtAction("GetLocation", new { id = location.LocationId }, location));
        }
示例#10
0
        public IActionResult CreateLocation([FromBody] LocationInsertDto location)
        {
            if (location == null)
            {
                return(BadRequest());
            }

            if (_locationRepository.isLocationExist(location.Name))
            {
                ModelState.AddModelError(nameof(LocationInsertDto), "Locaiton Name Already Exist");
            }

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

            var locationEntity = Mapper.Map <Location>(location);

            _locationRepository.Add(locationEntity);

            if (!_locationRepository.Commit())
            {
                throw new Exception("Creating a Locaiton Failed");
            }

            var locationtoReturn = Mapper.Map <LocationViewModel>(locationEntity);

            return(CreatedAtRoute("GetLocation", new { id = locationtoReturn.Id }, locationtoReturn));
        }
示例#11
0
        public int SaveLocation(LocationModel model)
        {
            var location = Mapper.DynamicMap <lkpLocation>(model);

            _locationRepository.Add(location);
            return(_locationRepository.SaveChanges());
        }
示例#12
0
        public bool approveGarage(Application application)
        {
            Garage   garage = new Garage();
            Location location = new Location();
            var      holder = applicationRepository.Update(application);
            bool     gar, loc;

            if (holder)
            {
                garage.garageName  = application.garageName;
                garage.username    = application.username;
                garage.password    = application.password;
                garage.email       = application.email;
                garage.phoneNumber = application.phoneNumber;
            }
            gar = garageRepository.Add(garage);

            var garageId = garageRepository.garages.Where(g => g.username == application.username).Select(g => g.Id).FirstOrDefault();

            if (garageId != 0)
            {
                location.ApplicationId = application.Id;
                location.GarageId      = garageId;
                location.longitude     = application.longitude;
                location.latitude      = application.lattitude;
            }

            loc = locationRepository.Add(location);

            return(gar && loc);
        }
示例#13
0
        public ActionResult PostLocation(Location location)
        {
            repo.Add(location);
            repo.SaveChanges();

            return(StatusCode(201));
        }
示例#14
0
        public async Task <IActionResult> CreateLocation([FromBody] PostedLocation location)
        {
            Int32 key;

            try
            {
                if (location == null || !ModelState.IsValid)
                {
                    return(BadRequest("Location body supplied is invalid!"));
                }

                if (string.IsNullOrWhiteSpace(location.Name) || string.IsNullOrWhiteSpace(location.Description))
                {
                    return(BadRequest("One or more required paramaters were empty."));
                }

                key = await _locationRepo.Add(location);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(BadRequest("Error while creating location!"));
            }

            return(Ok(key));
        }
示例#15
0
        public Guid SaveLocation(LocationModel data, SaveMode saveMode)
        {
            var location = locationRepository.Get(data.Id);

            if (saveMode == SaveMode.CreateNew)
            {
                if (location != null)
                {
                    throw new DataValidationException(string.Format(MessageResource.Error_UpdateDuplicateUniqeField, "location"));
                }
                location    = new Location();
                location.Id = Guid.NewGuid();
                locationRepository.Add(location);
            }
            else
            {
                if (location == null)
                {
                    throw new DataValidationException(string.Format(MessageResource.Error_DataNotFoundForUpdate, "Location"));
                }
            }

            location.Address    = data.Address;
            location.ProvinceId = data.ProvinceId;
            location.IsActive   = data.IsActive;
            unitOfWork.SaveChanges();

            return(location.Id);
        }
示例#16
0
        public async Task <IActionResult> CreateLocation([FromBody] LocationFormDto location)
        {
            var locationType = await _locationRepo.GetLocationType(location.LocationTypeId);

            if (locationType == null)
            {
                ModelState.AddModelError("error", "Location Type not found");
            }


            if (string.IsNullOrEmpty(location.Name))
            {
                ModelState.AddModelError("error", "Location name is required");
            }

            if (string.IsNullOrEmpty(location.Address))
            {
                ModelState.AddModelError("error", "Location Address is required");
            }


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

            var newLocation = new Location
            {
                Name         = location.Name,
                Address      = location.Address,
                Phone        = location.Phone,
                LocationType = locationType
            };

            _locationRepo.Add(newLocation);

            if (await _locationRepo.Save())
            {
                var locationToReturn = _mapper.Map <LocationDetailDto>(newLocation);

                return(CreatedAtRoute("GetLocation", new { controller = "Locations", id = newLocation.Id }, locationToReturn));
            }


            return(BadRequest(new { error = "Unabble to Create new Location" }));
        }
示例#17
0
        public ActionResult Index(Locations location)
        {
            var status = locationRepository.Add(location);

            Session["Status"]  = status ? "Success" : "Failed";
            Session["Message"] = status ? "Location Successfully Added" : "Location Addition Failed";
            return(RedirectToAction("Index"));
        }
示例#18
0
        public void CreateLocation(Location location)
        {
            if (location == null)
            {
                throw new Exception("Invalid location!");
            }

            locationRepository.Add(location);
        }
示例#19
0
        public async Task <IActionResult> Post(Guid memberId, [FromBody] Location location)
        {
            location.MemberId   = memberId;
            location.LocationId = Guid.NewGuid();
            location.Timestamp  = DateTime.Now;
            await _locationRepository.Add(location);

            return(CreatedAtRoute($"/api/locations/{memberId}/{location.LocationId}", location));
        }
示例#20
0
        public ActionResult PostLocation(Location location)
        {
            //location.
            if (!_repo.isLocationExist(location))
            {
                _repo.Add(location);
                return(StatusCode(201));
            }

            return(StatusCode(409));
        }
示例#21
0
 public ActionResult AddLocation(Location item)
 {
     if (ModelState.IsValid)
     {
         _repository.Add(item, User.Identity.Name);
         ViewBag.Message = "Upload successful";
         return(RedirectToAction("GetAllLocations"));
     }
     ViewBag.Message = "Upload failed";
     return(View(item));
 }
 public bool Add(LocationAddRequest location)
 {
     try
     {
         return(_locationRepository.Add(location));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public LocationViewModel InsertLocation(LocationBindingModel model)
        {
            var location = model.ToEntity();

            location = _locationRepository.Add(location);
            CurrentUnitOfWork.Commit();

            location = _locationRepository.FindOne(location.Id);
            var viewModel = location.ToViewModel();

            return(viewModel);
        }
示例#24
0
        public async Task <IActionResult> Modify([FromBody] Location item)
        {
            try
            {
                var res = await locationRepository.Add(item);

                return(Ok(res));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.GetBaseException().Message));
            }
        }
示例#25
0
 public CreateResponse Create(LocationRequest request)
 {
     try
     {
         var location = TypeAdapter.Adapt <Location>(request);
         _locationValidator.ValidateAndThrowException(location, "Base");
         _locationRepository.Add(location);
         return(new CreateResponse(location.Id));
     }
     catch (DataAccessException)
     {
         throw new ApplicationException();
     }
 }
示例#26
0
 public async Task <LocationDTO> AddLocation(LocationDTO location)
 {
     try
     {
         if (location.ImageId == 0)
         {
             location.ImageId = null;
         }
         return((await locationRepo.Add(location.ToEntity())).toDto());
     }
     catch (Exception e)
     {
         return(null);
     }
 }
示例#27
0
        public BaseViewModel <LocationViewModel> CreateLocation(CreateLocationRequestViewModel location)
        {
            var entity = _mapper.Map <Location>(location);

            entity.Id = Guid.NewGuid();
            entity.SetDefaultInsertValue(_repository.GetUsername());
            _repository.Add(entity);

            var result = new BaseViewModel <LocationViewModel>()
            {
                Data = _mapper.Map <LocationViewModel>(entity),
            };

            Save();

            return(result);
        }
        public ActionResult Create([Bind("Id,TesterId,Name")] Locations location)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    locationRepository.Add(location);
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch
            {
                return(NotFound());
            }

            ViewData["TesterId"] = new SelectList(testerRepository.GetAllTester(), "Id", "FullName", location.TesterId);
            return(View(location));
        }
示例#29
0
        public async Task <ActionResult <LocationDto> > PostLocation(LocationDto locationDto)
        {
            try
            {
                var mappedEntity = _mapper.Map <Location>(locationDto);
                _locationRepository.Add(mappedEntity);

                if (await _locationRepository.Save())
                {
                    return(Created($"/api/v1.0/cities/{mappedEntity.LocationId}", _mapper.Map <LocationDto>(mappedEntity)));
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}"));
            }
            return(BadRequest());
        }
        public void Add(SaveLocationMessage message)
        {
            var location = new Location();

            location.IP           = message.IP;
            location.Name         = message.Name;
            location.PublicType   = message.PublicType;
            location.Spot         = message.Spot;
            location.MonthlyValue = message.MonthlyValue;
            foreach (var pointVm in message.Points)
            {
                location.Points.Add(new Point {
                    Name = pointVm.Name
                });
            }

            _locationRepository.Add(location);
            _locationRepository.SaveChanges();
        }