/// <summary>
        /// Updates gallery data
        /// </summary>
        /// <param name="gallery"></param>
        /// <returns></returns>
        public static OperationResults UpdateGallery(CuratedGallery gallery, bool includePackage = false)
        {
            OperationResult<OperationResults, object> rslt = null;

            try
            {
                rslt = GalleryRepository.UpdateGallery(gallery, includePackage);
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex);
                throw;
            }

            return rslt.Result;
        }
 protected GalleryItemModel Convert(CuratedGallery item)
 {
     MappingData md = new MappingData(new string[]
         {
             Utils.GetPropertyName<CuratedGallery, GalleryPublicationPeriod>(x => x.PublicationPeriod),
             Utils.GetPropertyName<CuratedGallery, DateTime>(x => x.DateCreated),
             Utils.GetPropertyName<CuratedGallery, DateTime?>(x => x.DateModified)
         });
     var output = this.ObjectMapper.DoMapping<GalleryItemModel>(item, md);
     output.DateCreated = item.DateCreated.ToString(DateTimeFormat);
     output.DateModified = item.DateModified.HasValue ? item.DateModified.Value.ToString(DateTimeFormat) : null;
     output.PublicationPeriod = item.PublicationPeriod == null ? null : new Range<string>() { From = item.PublicationPeriod.Start.ToString(), To = item.PublicationPeriod.End.HasValue ? item.PublicationPeriod.End.Value.ToString() : null };
     return output;
 }
        public OperationResult<OperationResults, object> UpdateGallery(CuratedGallery gallery, bool includePackage = false)
        {
            using (var context = this.CreateMainContext())
            {
                if (context.Connection.State != System.Data.ConnectionState.Open)
                    context.Connection.Open();

                try
                {
                    context.Transaction = context.Connection.BeginTransaction();

                    var grec = context.CuratedGalleryRecords.Where(x => x.ID == gallery.ID).SingleOrDefault();

                    if (grec == null)
                        return new OperationResult<OperationResults, object>() { Result = OperationResults.NotFound };

                    this.ObjectMapper.DoMapping(gallery, grec, new MappingData(new string[] { "ID", "DateCreated", "Package" }));

                    if (includePackage)
                    {
                        var frec = context.FileRecords.Where(x => x.ID == grec.Archive).Single();
                        frec.Content = new System.Data.Linq.Binary(gallery.Package.FileContent);
                        frec.Name = gallery.Package.FileName;
                    }

                    context.SubmitChanges();

                    context.Transaction.Commit();
                }
                catch(Exception ex)
                {
                    if (context.Transaction != null)
                        context.Transaction.Rollback();

                    this.Logger.WriteError(ex);

                    throw;
                }
            }

            return new OperationResult<OperationResults, object>() { Result = OperationResults.Success };
        }