Exemplo n.º 1
0
        public void SaveCreditTransaction(ICreditTransaction document)
        {
            try
            {
                using (var context = IoC.Resolve <IAimpContext>())
                {
                    if (document.Id == 0)
                    {
                        document.UserId = CurrentUserProvider.User.Id;
                    }
                    else
                    {
                        ICreditTransaction dbTransaction = null;

                        if (document.Id != 0)
                        {
                            dbTransaction = context.CreditTransactions.Get(document.Id, x => x.DkpDocument, x => x.AgentDocument);
                        }

                        UserFileCheck.AddOrUpdate(context, document, document.DkpDocument, dbTransaction?.DkpDocument);
                        UserFileCheck.AddOrUpdate(context, document, document.AgentDocument, dbTransaction?.AgentDocument);
                    }
                    context.CreditTransactions.AddOrUpdate(document);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                LoggerProvider.Logger.Log(ex);
                throw;
            }
        }
Exemplo n.º 2
0
        public void SaveContractor(Contractor contractor)
        {
            try
            {
                CheckAddRight();

                if (contractor.Region.Id == 0)
                {
                    var values = new Dictionary <string, string>()
                    {
                        { "Name", contractor.Region.Name }
                    };
                    contractor.RegionId = Context.Regions.GetOrAdd(values).Id;
                    contractor.Region   = null;
                }
                if (contractor.City.Id == 0)
                {
                    var values = new Dictionary <string, string>()
                    {
                        { "Name", contractor.City.Name }, { "RegionId", contractor.RegionId.ToString() }
                    };
                    contractor.CityId = Context.Cities.GetOrAdd(values).Id;
                    contractor.City   = null;
                }
                Contractor dbContractor = null;

                if (contractor.Id != 0)
                {
                    dbContractor = Context.Contractors.Get(contractor.Id, x => x.Document, x => x.Photo);
                }

                UserFileCheck.AddOrUpdate(Context, contractor, contractor.Document, dbContractor?.Document);
                UserFileCheck.AddOrUpdate(Context, contractor, contractor.Photo, dbContractor?.Photo);
                if (contractor.LegalPerson != null)
                {
                    Context.LegalPersons.AddOrUpdate(contractor.LegalPerson);
                }

                Context.Contractors.AddOrUpdate(contractor);
                Context.SaveChanges();
            }
            catch (AccessDeniedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Instance.Log(ex);

                throw new Exception("Неудалось сохранить контрагента, обратитесь к администратору");
            }
        }
Exemplo n.º 3
0
        public SaveEntityResult SaveContractor(IContractor contractor)
        {
            try
            {
                using (var context = IoC.Resolve <IAimpContext>())
                {
                    if (contractor.Region.Id == 0)
                    {
                        var values = new Dictionary <string, string>()
                        {
                            { "Name", contractor.Region.Name }
                        };
                        contractor.RegionId = context.Regions.GetOrAdd(values).Id;
                        contractor.Region   = null;
                    }
                    if (contractor.City.Id == 0)
                    {
                        var values = new Dictionary <string, string>()
                        {
                            { "Name", contractor.City.Name }, { "RegionId", contractor.RegionId.ToString() }
                        };
                        contractor.CityId = context.Cities.GetOrAdd(values).Id;
                        contractor.City   = null;
                    }
                    IContractor dbContractor = null;

                    if (contractor.Id != 0)
                    {
                        dbContractor = context.Contractors.Get(contractor.Id, x => x.Document, x => x.Photo);
                    }

                    UserFileCheck.AddOrUpdate(context, contractor, contractor.Document, dbContractor?.Document);
                    UserFileCheck.AddOrUpdate(context, contractor, contractor.Photo, dbContractor?.Photo);
                    if (contractor.LegalPerson != null)
                    {
                        context.LegalPersons.AddOrUpdate(contractor.LegalPerson);
                    }

                    context.Contractors.AddOrUpdate(contractor);
                    context.SaveChanges();
                }
                return(new SaveEntityResult()
                {
                    Id = contractor.Id
                });
            }
            catch (Exception ex)
            {
                LoggerProvider.Logger.Log(ex);
                throw;
            }
        }
        public void SaveDocument(CreditTransactionDocument document)
        {
            try
            {
                CheckAddRight();

                var creditTransaction = TinyMapper.Map <CreditTransaction>(document);
                if (creditTransaction.Id == 0)
                {
                    creditTransaction.UserId = User.Id;
                }
                else
                {
                    CreditTransaction dbTransaction = null;

                    if (creditTransaction.Id != 0)
                    {
                        dbTransaction = Context.CreditTransactions.Get(creditTransaction.Id, x => x.DkpDocument, x => x.AgentDocument);
                    }

                    UserFileCheck.AddOrUpdate(Context, creditTransaction, creditTransaction.DkpDocument, dbTransaction?.DkpDocument);
                    UserFileCheck.AddOrUpdate(Context, creditTransaction, creditTransaction.AgentDocument, dbTransaction?.AgentDocument);
                }
                Context.CreditTransactions.AddOrUpdate(creditTransaction);
                Context.SaveChanges();
                document.Id = creditTransaction.Id;
                //document.Number = Context.CreditTransactions.Get(creditTransaction.Id).Number;
            }
            catch (AccessDeniedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Instance.Log(ex);

                throw new Exception("Неудалось сохранить документ");
            }
        }
Exemplo n.º 5
0
        public void SaveTrancport(Trancport trancport)
        {
            try
            {
                CheckAddRight();

                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;
                }
                Trancport 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();
            }
            catch (AccessDeniedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Instance.Log("SaveTrancport", ex);

                throw new Exception("Неудалось сохранить транспорт, обратитесь к администратору");
            }
        }
Exemplo n.º 6
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;
            }
        }