Пример #1
0
        public async Task <Location> GetLocationById(int?id, int?serverId = -1)
        {
            if (serverId == -1)
            {
                serverId = _externalPlatformService.LocalId();
            }

            if (id == null || serverId == null)
            {
                throw new Exception("Null id");
            }
            if (_externalPlatformService.IsForeign((int)serverId))
            {
                return(await _externalPlatformService.GetLocation((int)id, (int)serverId));
            }
            var location = await _context.FindAsync <Location>(id);

            if (location == null)
            {
                throw new Exception("Location doesn't exist");
            }
            return(location);
        }
Пример #2
0
        public async Task <CheckResult> Checkin(int Id, ApplicationUser user = null, int serverId = 2)
        {
            try
            {
                Location location;
                try { location = await _locationService.GetLocationById(Id, serverId); }
                catch (Exception ex)
                {
                    return(new CheckResult {
                        successful = false, message = ex.Message
                    });
                }

                if (location.CantidadPersonasDentro >= location.Capacidad)
                {
                    return(new CheckResult {
                        successful = false, message = String.Format("El sitio {0} esta lleno ", location.Nombre)
                    });
                }



                if (user != null)
                {
                    var Result = new CheckResult {
                        successful = true, message = ""
                    };

                    if (user.Infected)
                    {
                        Result.successful = false;
                        Result.message    = "User is infected and can't check in";
                    }
                    else if (user.CurrentStayId != null)
                    {
                        Result.successful = false;
                        Result.message    = "User is already checked in at a location";
                    }

                    if (!Result.successful)
                    {
                        return(Result);
                    }
                }

                if (_externalPlatformService.IsForeign(serverId))
                {
                    try
                    {
                        await _externalPlatformService.ExternalCheckIn(Id, serverId);
                    }
                    catch (Exception ex)
                    {
                        return(new CheckResult {
                            successful = false, message = ex.Message
                        });
                    }
                }
                else
                {
                    location.CantidadPersonasDentro++;
                    _context.Update(location);

                    await _context.SaveChangesAsync();
                }

                if (user != null)
                {
                    await CreateStay(user, Id, serverId);
                }
                ;

                return(new CheckResult {
                    successful = true, message = "Checkin realizado con exito"
                });
            }
            catch (DbUpdateConcurrencyException) { }

            return(new CheckResult {
                successful = false, message = "Alguien más quiso entrar antes que vos"
            });
        }