Ejemplo n.º 1
0
 public void Update(CustomerPack entity)
 {
     RetryableOperation.Invoke(ExceptionPolicies.General, () =>
     {
         _customerPackRepository.Update(entity);
         _unitOfWork.Save();
     });
 }
Ejemplo n.º 2
0
        public int Create(CustomerPack entity)
        {
            RetryableOperation.Invoke(ExceptionPolicies.General, () =>
            {
                _customerPackRepository.Insert(entity);
                _unitOfWork.Save();
            });

            return(entity.Id);
        }
Ejemplo n.º 3
0
        public CustomerPack GetById(int id)
        {
            CustomerPack result = null;

            RetryableOperation.Invoke(ExceptionPolicies.General, () =>
            {
                result = _customerPackRepository.GetById(id);
            });
            return(result);
        }
Ejemplo n.º 4
0
        public CustomerPack GetByCustomerAndId(int customerId, int id)
        {
            CustomerPack result = null;

            RetryableOperation.Invoke(ExceptionPolicies.General, () =>
            {
                result = _customerPackRepository
                         .Query(q => q.CustomerId == customerId && q.Id == id)
                         .SingleOrDefault();
            });
            return(result);
        }
Ejemplo n.º 5
0
        public ActionResult AddCustomerPack(AddCustomerPackViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (_appUserContext.Current.CurrentCustomer != null)
                    {
                        // Get the level.
                        var level = model.EditLevel.GetEnumIntFromText <LevelName>();

                        // Get all the diagrams for this level.
                        var diagrams = _diagramService
                                       .Diagrams(_appUserContext.Current.CurrentCustomer.Id)
                                       .Where(x => x.Level == level)
                                       .ToList();

                        using (var zipMemoryStream = new MemoryStream())
                        {
                            // Build the archive
                            using (var zipArchive = new ZipArchive(zipMemoryStream, ZipArchiveMode.Create, true))
                            {
                                var i = 1;
                                foreach (var diagram in diagrams)
                                {
                                    var zipArchiveEntry = zipArchive.CreateEntry(string.Format("{0:000}", i++) + diagram.Filename);
                                    using (var zipArchiveEntryStream = zipArchiveEntry.Open())
                                    {
                                        zipArchiveEntryStream.Write(diagram.DiagramData, 0 /* offset */,
                                                                    diagram.DiagramData.Length);
                                    }
                                }
                            }

                            //Rewind the stream for reading to output.
                            zipMemoryStream.Seek(0, SeekOrigin.Begin);

                            // Create a new Customer Pack entity.
                            var now          = DateTime.Now;
                            var customerPack = new CustomerPack
                            {
                                CustomerId   = _appUserContext.Current.CurrentCustomer.Id,
                                Filename     = model.Filename,
                                Level        = level,
                                MimeType     = MimeTypeNames.Zip,
                                PackData     = zipMemoryStream.ToArray(),
                                PackNotes    = model.PackNotes,
                                InsertedDate = now,
                                InsertedBy   = _contextManager.UserManager.Name,
                                UpdatedDate  = now,
                                UpdatedBy    = _contextManager.UserManager.Name
                            };

                            _customerPackService.Create(customerPack);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _contextManager.ResponseManager.StatusCode = 500;
                    _contextManager.ResponseManager.AppendHeader(ModelStateErrorNames.ErrorMessage, ex.Message);
                    ExceptionPolicy.HandleException(ex, ExceptionPolicies.General);
                }
            }
            return(CustomerPack());
        }