Пример #1
0
        public Result <IEnumerable <SgtinViewModel> > Get(int id)
        {
            try
            {
                var sgtinDataBase       = new SgtinDataBase(ConnectionStringPattern, Login, Password);
                var naklAcceptTypeId    = sgtinDataBase.GetNaklAcceptTypeId(id);
                var sgtinStatusDataBase = new SgtinStatusDataBase(ConnectionStringPattern, Login, Password);
                var statuses            = sgtinStatusDataBase.GetAll();

                if (naklAcceptTypeId == 1)
                {
                    return(new Result <IEnumerable <SgtinViewModel> >(sgtinDataBase.GetStinResult(id).Select((x) =>
                    {
                        var s = new SgtinViewModel()
                        {
                        };

                        if (x.ProviderSgtin != null && x.ReceiverSgtin == null)
                        {
                            //не проверен
                            s.status = statuses.First((z) => z.Id == 3).Value;
                            s.style = statuses.First((z) => z.Id == 3).Style;
                            s.sgtin = x.ProviderSgtin;
                        }
                        else if (x.ProviderSgtin == null && x.ReceiverSgtin != null)
                        {
                            //лишний
                            s.status = statuses.First((z) => z.Id == 4).Value;
                            s.style = statuses.First((z) => z.Id == 4).Style;
                            s.sgtin = x.ReceiverSgtin;
                        }
                        else if (x.ProviderSgtin != null & x.ReceiverSgtin != null)
                        {
                            //совпадает
                            s.status = statuses.First((z) => z.Id == 2).Value;
                            s.style = statuses.First((z) => z.Id == 2).Style;
                            s.sgtin = x.ProviderSgtin;
                        }
                        return s;
                    }).ToList()));
                }
                else
                {
                    return(new Result <IEnumerable <SgtinViewModel> >(sgtinDataBase.Get(id).Select((x) => new SgtinViewModel()
                    {
                        sgtin = x.Value,
                        status = statuses.First((z) => z.Id == 1).Value,
                        style = statuses.First((z) => z.Id == 1).Style
                    })));
                }
            }
            catch (Exception e)
            {
                return(new Result <IEnumerable <SgtinViewModel> >(e.Message));
            }
        }
Пример #2
0
        public Result <object> Post(int?id, string[] sgtins, int?nakl_item_id = null)
        {
            try
            {
                var sgtinDataBase = new SgtinDataBase(ConnectionStringPattern, Login, Password);

                return(new Result <object>(
                           sgtinDataBase.AddNewSgtin(naklId: id, naklItemId: nakl_item_id, sgtins: sgtins)
                           .Select((x) => new AddSgtinResultViewModel()
                {
                    sgtin = x.Sgtin,
                    gtin = x.Gtin,
                    status = x.Status,
                    nakl_item_id = x.NaklItemId,
                    gtin_same_as_current = x.GtinSameAsCurrent,
                    style = x.Style
                })
                           ));
            }
            catch (Exception e)
            {
                return(new Result <object>(e.Message));
            }
        }
Пример #3
0
 public object GetService(Type serviceType)
 {
     if (serviceType == typeof(UsersController))
     {
         var dataBase   = new UserDataBase(connectionString);
         var controller = new UsersController(dataBase);
         AddInstance(serviceType, controller);
         return(controller);
     }
     else if (serviceType == typeof(NaklStatusesController))
     {
         var dataBase   = new NaklStatusDataBase(connectionString);
         var controller = new NaklStatusesController(dataBase);
         AddInstance(serviceType, controller);
         return(controller);
     }
     else if (serviceType == typeof(SgtinsController))
     {
         var sgtinDataBase    = new SgtinDataBase(connectionString);
         var naklDataBase     = new NaklDataBase(connectionString);
         var naklItemDateBase = new NaklItemDataBase(connectionString);
         var controller       = new SgtinsController(sgtinDataBase, naklDataBase, naklItemDateBase);
         AddInstance(serviceType, controller);
         return(controller);
     }
     else if (serviceType == typeof(AddressesController))
     {
         var dataBase   = new AddressDataBase(connectionString);
         var controller = new AddressesController(dataBase);
         AddInstance(serviceType, controller);
         return(controller);
     }
     else if (serviceType == typeof(NaklsController))
     {
         var naklDataBase     = new NaklDataBase(connectionString);
         var naklItemDataBase = new NaklItemDataBase(connectionString);
         var controller       = new NaklsController(naklDataBase, naklItemDataBase);
         AddInstance(serviceType, controller);
         return(controller);
     }
     else if (serviceType == typeof(NaklItemsController))
     {
         var dataBase  = new NaklItemDataBase(connectionString);
         var controler = new NaklItemsController(dataBase);
         AddInstance(serviceType, controler);
         return(controler);
     }
     else if (serviceType == typeof(CompaniesController))
     {
         var dataBase   = new CompanyDataBase(connectionString);
         var controller = new CompaniesController(dataBase);
         AddInstance(serviceType, controller);
         return(controller);
     }
     else if (serviceType == typeof(ReceiveTypesController))
     {
         var dataBase   = new RecesiverTypeDataBase(connectionString);
         var controller = new ReceiveTypesController(dataBase);
         AddInstance(serviceType, controller);
         return(controller);
     }
     else if (serviceType == typeof(ContractTypesController))
     {
         var dataBase   = new ContractTypeDataBase(connectionString);
         var controller = new ContractTypesController(dataBase);
         AddInstance(serviceType, controller);
         return(controller);
     }
     else if (serviceType == typeof(SourceTypesController))
     {
         var dataBase   = new SourceTypDataBase(connectionString);
         var controller = new SourceTypesController(dataBase);
         AddInstance(serviceType, controller);
         return(controller);
     }
     else
     {
         return(null);
     }
 }