コード例 #1
0
        public async Task <ServiceResponseObject <BaseResponseObject> > SetContainerLocation(LocationViewModel model)
        {
            if (ModelState.IsValid)
            {
                ContainerMethods BoxData = new ContainerMethods(_boxContext);
                var Result = await BoxData.SetContainerLocation(model);

                return(Result);
            }

            ServiceResponseObject <BaseResponseObject> response = new ServiceResponseObject <BaseResponseObject>();

            response.Status = ResponseResult.Error;

            List <string> errors = ModelState.Values.Aggregate(
                new List <string>(),
                (a, c) =>
            {
                a.AddRange(c.Errors.Select(r => r.ErrorMessage));
                return(a);
            },
                a => a
                );

            response.Message = errors[0];
            return(response);
        }
コード例 #2
0
        public async Task <ServiceResponseObject <ContainerResponse> > Create(string name)
        {
            ContainerMethods BoxData = new ContainerMethods(_boxContext);
            var Result = await BoxData.Create(name);

            return(Result);
        }
コード例 #3
0
        public async Task <ServiceResponseObject <BaseResponseObject> > SearchCommandPhoto(string name)
        {
            ContainerMethods BoxData = new ContainerMethods(_boxContext);
            var Result = await BoxData.SearchCommandPhoto(name);

            return(Result);
        }
コード例 #4
0
        public async Task <ServiceResponseObject <ListResponse <ContainerResponse> > > GetBoxesByName(string name)
        {
            ContainerMethods BoxData = new ContainerMethods(_boxContext);
            var Result = await BoxData.GetBoxesByName(name);

            return(Result);
        }
コード例 #5
0
        public async Task <ServiceResponseObject <BoxDataResponse> > GetBox(Guid id, Guid driverId, Guid orderId)
        {
            ContainerMethods BoxData = new ContainerMethods(_boxContext);
            var Result = await BoxData.GetBox(id);

            if (Result.Status == ResponseResult.OK)
            {
                if (SearchDriver(driverId))
                {
                    OrderHasBox order = new OrderHasBox
                    {
                        BoxId   = Result.ResponseData.Id,
                        IsBusy  = true,
                        OrderId = orderId
                    };

                    DriverHasBox hasBox = new DriverHasBox
                    {
                        BoxId    = Result.ResponseData.Id,
                        DriverId = driverId
                    };
                    _boxContext.DriverHasBoxes.Add(hasBox);
                    _boxContext.OrderHasBoxes.Add(order);
                    _boxContext.SaveChanges();
                    Result.Message += " Контейнер привязан.";
                }
            }
            return(Result);
        }
コード例 #6
0
        public static async Task <IActionResult> Login([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log)
        {
            var        requestBody  = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic    credenciales = JsonConvert.DeserializeObject(requestBody);
            string     clientId     = Environment.GetEnvironmentVariable("clientID", EnvironmentVariableTarget.Process);
            string     scope        = Environment.GetEnvironmentVariable("scope", EnvironmentVariableTarget.Process);
            string     clientSecret = Environment.GetEnvironmentVariable("clientSecret", EnvironmentVariableTarget.Process);
            string     username     = (string)credenciales["username"];
            string     password     = (string)credenciales["password"];
            string     grantType    = "password";
            string     tenant       = Environment.GetEnvironmentVariable("tenant", EnvironmentVariableTarget.Process);
            string     endPoint     = $"https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token";
            HttpClient client       = new HttpClient();
            var        parametros   = new Dictionary <string, string> {
                { "client_id", clientId },
                { "scope", scope },
                { "client_secret", clientSecret },
                { "username", username },
                { "password", password },
                { "grant_type", grantType }
            };
            var requestMessage = new HttpRequestMessage(HttpMethod.Post, endPoint);

            requestMessage.Content = new FormUrlEncodedContent(parametros);
            var response = await client.SendAsync(requestMessage);

            var responseBody = await response.Content.ReadAsStringAsync();

            dynamic json = JsonConvert.DeserializeObject(responseBody);

            client.Dispose();
            string accessToken = json.access_token;

            return(ContainerMethods.GetJsonGetContainer(OperationHelper.GetElement(accessToken), log));
        }
コード例 #7
0
        public static async Task Handler(
            [ServiceBusTrigger("agroqueue", Connection = "ServiceBusConnectionString", IsSessionsEnabled = true)] Message message,
            [SignalR(HubName = "AsyncConnection")] IAsyncCollector <SignalRMessage> signalRMessages,
            ILogger log)
        {
            var opInstance  = ServiceBus.Deserialize(message.Body);
            var ObjectIdAAD = opInstance.Value <string>("ObjectIdAAD");
            var queries     = new CommonQueries(ConfigManager.GetDbArguments);
            var userId      = await queries.GetUserIdFromAAD(ObjectIdAAD);

            var EntityName = opInstance.Value <string>("EntityName");
            var agro       = await ContainerMethods.AgroManager(ObjectIdAAD, false);

            var     entityType = opInstance["EntityType"].ToObject <Type>();
            var     repo       = agro.GetOperationByInputType(entityType);
            dynamic element    = opInstance["Element"].ToObject(entityType);

            element.Id = opInstance.Value <string>("Id");
            try {
                var saveReturn = await repo.SaveInput(element, false);

                await agro.UserActivity.SaveInput(new UserActivityInput {
                    Action     = opInstance.Value <string>("HttpMethod").Equals("post") ? UserActivityAction.CREATE : UserActivityAction.MODIFY,
                    Date       = DateTime.Now,
                    EntityName = EntityName,
                    EntityId   = saveReturn.IdRelated
                }, false);

                await signalRMessages.AddAsync(new SignalRMessage { Target = "Success", UserId = userId, Arguments = new object[] { EntityName } });
            }
            catch (Exception ex) {
                log.LogError(ex, ex.Message);
                await signalRMessages.AddAsync(new SignalRMessage { Target = "Error", UserId = userId, Arguments = new object[] { ex is Validation_Exception ? ((Validation_Exception)ex).ErrorMessages : (object)new string[] { $"{ex.Message}" } } });
            }
        }
コード例 #8
0
        public async Task <JsonResult> GetBoxesLocation()
        {
            ContainerMethods BoxData = new ContainerMethods(_boxContext);
            JsonResult       result  = null;
            var data = await BoxData.GetBoxesLocation();

            var boxes = data.ResponseData.Objects;

            result = new JsonResult(boxes);
            return(result);
        }
コード例 #9
0
        public static async Task <ActionResultWithId> HttpProcessing <DbElement, InputElement>(HttpRequest req, ILogger log, string ObjectIdAAD, Func <IAgroManager <GeographyPoint>, IGenericOperation <DbElement, InputElement> > repo, InputElement element) where DbElement : DocumentBase where InputElement : InputBase
        {
            var method = req.Method.ToLower();

            switch (method)
            {
            case "get":
                if (!string.IsNullOrWhiteSpace(element.Id))
                {
                    var manager = await ContainerMethods.AgroManager(ObjectIdAAD);

                    var elementDb = await repo(manager).Get(element.Id);

                    return(new ActionResultWithId {
                        Id = element.Id,
                        JsonResult = ContainerMethods.GetJsonGetContainer(elementDb, log)
                    });
                }
                return(new ActionResultWithId {
                    Id = null,
                    JsonResult = ContainerMethods.GetJsonGetContainer(new ExtGetContainer <string> {
                        ErrorMessage = "Id obligatorio", StatusResult = ExtGetDataResult.Error
                    }, log)
                });

            default:

                string EntityName = ((DbElement)Activator.CreateInstance(typeof(DbElement))).CosmosEntityName;

                var opInstance = new OperationInstance <InputElement>(element, element.Id, EntityName, method, ObjectIdAAD);


                try
                {
                    await ServiceBus.PushElement(opInstance, EntityName);
                }
                catch (Exception e)
                {
                    Console.WriteLine("error en el service bus");
                }

                return(new ActionResultWithId {
                    Id = null,
                    JsonResult = new JsonResult("Operacion en cola.")
                });
            }
        }
コード例 #10
0
        public async Task <ServiceResponseObject <BoxDataResponse> > GetBoxForUser(string userId)
        {
            ContainerMethods BoxData = new ContainerMethods(_boxContext);
            var access = await _boxContext.UserHasAccesses.Where(p => p.UserId == userId).FirstOrDefaultAsync();

            if (access != null)
            {
                var Result = await BoxData.GetBox(access.BoxId);

                Result.Message += " Оплатите заказ.";
                return(Result);
            }
            ServiceResponseObject <BoxDataResponse> response = new ServiceResponseObject <BoxDataResponse>();

            response.Message = "Нет доступа.";
            response.Status  = ResponseResult.Error;
            return(response);
        }
コード例 #11
0
        public static async Task <IActionResult> Initialize([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, ILogger log)
        {
            var claims = await Auth.Validate(req);

            if (claims == null)
            {
                return(new UnauthorizedResult());
            }
            string ObjectIdAAD = claims.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
            var    manager     = await ContainerMethods.AgroManager(ObjectIdAAD, true);

            string json = await req.ReadAsStringAsync();

            JObject jsonObject    = JObject.Parse(json);
            var     dbInitializer = new CosmosDbInitializer(manager, jsonObject.Value <string>("Assembly_Inputs"), jsonObject.Value <string>("Assembly_Entities"));
            var     result        = await dbInitializer.MapJsonToDB(jsonObject.Value <JObject>("Entities"));

            return(result);
        }
コード例 #12
0
        public static async Task <ActionResultWithId> HttpProcessing <DbElement, InputElement>(HttpRequest req, ILogger log, string ObjectIdAAD, Func <IAgroManager, IGenericOperation <DbElement, InputElement> > repo, InputElement element) where DbElement : DocumentBase where InputElement : InputBase
        {
            var method = req.Method.ToLower();

            switch (method)
            {
            case "get":
                if (!string.IsNullOrWhiteSpace(element.Id))
                {
                    var manager = await ContainerMethods.AgroManager(ObjectIdAAD, false);

                    var elementDb = await repo(manager).Get(element.Id);

                    return(new ActionResultWithId {
                        Id = element.Id,
                        JsonResult = ContainerMethods.GetJsonGetContainer(elementDb, log)
                    });
                }
                return(new ActionResultWithId {
                    Id = null,
                    JsonResult = ContainerMethods.GetJsonGetContainer(new ExtGetContainer <string> {
                        ErrorMessage = "Id obligatorio", StatusResult = ExtGetDataResult.Error
                    }, log)
                });

            default:
                //ExtPostContainer<string> saveReturn;
                string EntityName = ((DbElement)Activator.CreateInstance(typeof(DbElement))).CosmosEntityName;
                var    opInstance = new OperationInstance <InputElement>(element, element.Id, EntityName, method, ObjectIdAAD);
                await ServiceBus.PushElement(opInstance, EntityName);

                return(new ActionResultWithId {
                    Id = null,
                    JsonResult = new JsonResult("Operacion en cola.")
                });
                //try {
                //    saveReturn = await repo.SaveInput(element, false);
                //    await recordAcitvity.SaveInput(new UserActivityInput {
                //        Action = method.Equals("post") ? UserActivityAction.CREATE : UserActivityAction.MODIFY,
                //        Date = DateTime.Now,
                //        EntityName = ((DbElement)Activator.CreateInstance(typeof(DbElement))).CosmosEntityName,
                //        EntityId = saveReturn.IdRelated
                //    }, false);
                //}
                //catch (Exception ex) {
                //    var extPostError = new ExtPostErrorContainer<string> {
                //        InternalException = ex,
                //        Message = ex.Message,
                //        MessageResult = ExtMessageResult.Error
                //    };
                //    if (ex is Validation_Exception)
                //        extPostError.ValidationMessages = ((Validation_Exception)ex).ErrorMessages;
                //    return new ActionResultWithId {
                //        Id = null,
                //        JsonResult = ContainerMethods.GetJsonPostContainer(extPostError, log)
                //    };
                //}
                //return new ActionResultWithId {
                //    Id = saveReturn.IdRelated,
                //    JsonResult = ContainerMethods.GetJsonPostContainer(saveReturn, log)
                //};
            }
        }