Пример #1
0
        public void SaveDocument(CardTrancportDocument document)
        {
            try
            {
                CheckAddRight();
                var firstCardTrancport = document.CardTrancport;
                if (firstCardTrancport.Id == 0)
                {
                    firstCardTrancport.CommissionTransaction.UserId = User.Id;
                    foreach (var iPreCheks in document.PreChecks)
                    {
                        iPreCheks.CardTrancport = firstCardTrancport;

                        Context.PreChecksCardTrancport.AddOrUpdate(iPreCheks);
                    }
                }
                else
                {
                    var oldPreCheks = Context.PreChecksCardTrancport
                                      .All()
                                      .Where(x => x.CardTrancport.Id == firstCardTrancport.Id)
                                      .ToList();
                    foreach (var iPreCheck in oldPreCheks)
                    {
                        var preCheck =
                            document.PreChecks.FirstOrDefault(
                                x => x.Id == iPreCheck.Id);
                        if (preCheck == null)
                        {
                            Context.PreChecksCardTrancport.Delete(iPreCheck);
                        }
                        else
                        {
                            Context.PreChecksCardTrancport.AddOrUpdate(preCheck);
                        }
                    }
                    foreach (var iNewPreCheck in document.PreChecks.Where(x => x.Id == 0))
                    {
                        Context.PreChecksCardTrancport.AddOrUpdate(iNewPreCheck);
                    }
                }
                Context.CardsTrancport.AddOrUpdate(firstCardTrancport);
                Context.SaveChanges();
            }
            catch (AccessDeniedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Instance.Log(ex);
                throw new Exception("Не удалось сохранить документ, обратитесь к администратору");
            }
        }
Пример #2
0
        public void SaveCardTrancport(CardTrancportDocument document)
        {
            try
            {
                using (var context = IoC.Resolve <IAimpContext>())
                {
                    var firstCardTrancport = document.CardTrancport;
                    if (firstCardTrancport.Id == 0)
                    {
                        firstCardTrancport.CommissionTransaction.UserId = CurrentUserProvider.Account.Id;
                        foreach (var iPreCheks in document.PreChecks)
                        {
                            iPreCheks.CardTrancport = firstCardTrancport;

                            context.PreChecksCardTrancport.AddOrUpdate(iPreCheks);
                        }
                    }
                    else
                    {
                        var oldPreCheks = context.PreChecksCardTrancport
                                          .All()
                                          .Where(x => x.CardTrancport.Id == firstCardTrancport.Id)
                                          .ToList();
                        foreach (var iPreCheck in oldPreCheks)
                        {
                            var preCheck =
                                document.PreChecks.FirstOrDefault(
                                    x => x.Id == iPreCheck.Id);
                            if (preCheck == null)
                            {
                                context.PreChecksCardTrancport.Delete(iPreCheck);
                            }
                            else
                            {
                                context.PreChecksCardTrancport.AddOrUpdate(preCheck);
                            }
                        }
                        foreach (var iNewPreCheck in document.PreChecks.Where(x => x.Id == 0))
                        {
                            context.PreChecksCardTrancport.AddOrUpdate(iNewPreCheck);
                        }
                    }
                    context.CardsTrancport.AddOrUpdate(firstCardTrancport);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                LoggerProvider.Logger.Log(ex);
                throw;
            }
        }
 public CardTrancportViewModel(int?id)
 {
     using (var service = new AimpService())
     {
         if (id != null)
         {
             var response = service.GetCardTrancport((int)id);
             if (response.Error)
             {
                 throw new Exception(response.Message);
             }
             _document                = response.Document;
             CardTrancport            = response.Document.CardTrancport;
             _cardTrancportForCompare = TinyMapper.Map <CardTrancport>(CardTrancport);
             var preChecks = response.Document.PreChecks.Select(x => new PreCheckCardTrancportViewModel()
             {
                 CardTrancportId = x.Id,
                 Date            = x.Date,
                 Enable          = true,
                 Name            = x.Name,
                 Paid            = x.Paid,
                 Card            = x.Card,
                 PriceForClient  = x.PriceForClient,
                 Summ            = x.Summ
             });
             PreCheks = new ObservableCollection <PreCheckCardTrancportViewModel>(preChecks);
         }
         else
         {
             _document                = new CardTrancportDocument();
             CardTrancport            = new CardTrancport();
             _cardTrancportForCompare = new CardTrancport();
             PreCheks = new ObservableCollection <PreCheckCardTrancportViewModel>();
         }
         var responseStatuses = service.GetStatusesCard();
         if (responseStatuses.Error)
         {
             throw new Exception(responseStatuses.Message);
         }
         CardTrancport.StatusCardTrancport = responseStatuses.Items.FirstOrDefault(x => x.Id == CardTrancport.StatusCardTrancport?.Id);
         StatusesCardTrancport             = new ObservableCollection <StatusCardTrancport>(responseStatuses.Items);
     }
 }
Пример #4
0
        public SaveEntityResult SaveCardTrancport(CardTrancportDocument document)
        {
            try
            {
                _WriteLineConsole($"save card trancport: {document.Identity}");
                using (var helper = new CardsTrancportHelper())
                    helper.SaveCard(document);

                return(new SaveEntityResult()
                {
                    Message = "Данные успешно сохраненны", Id = document.CardTrancport.Id
                });
            }
            catch (Exception ex)
            {
                _WriteLineError($"save card trancport: {document?.Identity}", ex.Message);
                return(new SaveEntityResult()
                {
                    Error = true,
                    Message = ex.Message
                });
            }
        }
Пример #5
0
 public void SaveCardTrancport(CardTrancportDocument document)
 {
     throw new NotImplementedException();
 }
Пример #6
0
 public void SaveCard(CardTrancportDocument document)
 {
     _logic.SaveDocument(document);
 }