public TrancportInfoViewModel(Trancport trancport, IObjectSetValue window)
        {
            _window = window;

            if (trancport.Id > 0)
            {
                EditableTrancport = TinyMapper.Map <Trancport>(trancport);
            }
            else
            {
                EditableTrancport = new Trancport();
            }
            _trancport = trancport;
            _models    = TracnportInformation.Info.Models;

            Makes = new ObservableCollection <MakeTrancport>(TracnportInformation.Info.Makes);

            Categories = new ObservableCollection <TrancportCategory>(TracnportInformation.Info.Categories);

            TrancportTypes = new ObservableCollection <TrancportType>(TracnportInformation.Info.Types);

            EngineTypes = new ObservableCollection <EngineType>(TracnportInformation.Info.EngineTypes);

            MakeTrancport = EditableTrancport?.Make?.Name; // hack crazy
        }
Beispiel #2
0
        public SaveEntityResult SaveTrancport(ITrancport trancport)
        {
            try
            {
                using (var context = IoC.Resolve <IAimpContext>())
                {
                    if (trancport.Category?.Id == 0)
                    {
                        trancport.Category = context.TrancportCategories.GetOrAdd(new Dictionary <string, string>()
                        {
                            { "Name", trancport.Category.Name }
                        });
                    }
                    if (trancport.EngineType?.Id == 0)
                    {
                        trancport.EngineType = context.EngineTypes.GetOrAdd(new Dictionary <string, string>()
                        {
                            { "Name", trancport.EngineType.Name }
                        });
                    }

                    if (trancport.Type?.Id == 0)
                    {
                        trancport.Type = context.TrancportTypes.GetOrAdd(new Dictionary <string, string>()
                        {
                            { "Name", trancport.Type.Name }
                        });
                    }
                    if (trancport.Make.Id == 0)
                    {
                        var values = new Dictionary <string, string>()
                        {
                            { "Name", trancport.Make.Name }
                        };
                        trancport.MakeId = context.Regions.GetOrAdd(values).Id;
                        trancport.Make   = null;
                    }
                    if (trancport.Model.Id == 0)
                    {
                        var values = new Dictionary <string, string>()
                        {
                            { "Name", trancport.Model.Name }, { "MakeId", trancport.MakeId.ToString() }
                        };
                        trancport.ModelId = context.Cities.GetOrAdd(values).Id;
                        trancport.Model   = null;
                    }
                    ITrancport dbTrancport = null;

                    if (trancport.Id != 0)
                    {
                        dbTrancport = context.Trancports.Get(trancport.Id, x => x.CopyPts);
                    }

                    UserFileCheck.AddOrUpdate(context, trancport, trancport.CopyPts, dbTrancport?.CopyPts);
                    context.Trancports.AddOrUpdate(trancport);

                    context.SaveChanges();
                }
                return(new SaveEntityResult()
                {
                    Id = trancport.Id
                });
            }
            catch (Exception ex)
            {
                LoggerProvider.Logger.Log(ex);
                throw;
            }
        }
Beispiel #3
0
 public SaveEntityResult SaveTrancport(ITrancport trancport)
 {
     throw new NotImplementedException();
 }