Example #1
0
        /// <summary>
        /// Zapisywanie uprawnień do bazy danych
        /// </summary>
        /// <param name="device">Nośnik</param>
        /// <returns>Odpowiedź o stanie zapisu</returns>
        public ApiResponse Save(Device device)
        {
            var response = new ApiResponse();

            try
            {
                if (device.Id == 0)
                {
                    dynamic dbEntry = new Device();

                    dbEntry.Name   = device.Name;
                    dbEntry.UserId = device.UserId;
                    dbEntry.TypeId = device.TypeId;
                    SetRelation(device, ref dbEntry);
                    dbEntry.Description = device.Description;
                    Context.Devices.Add(dbEntry);
                }
                else
                {
                    dynamic dbEntry = Context.Devices.Find(device.Id);
                    if (dbEntry != null)
                    {
                        SetRelation(device, ref dbEntry);

                        dbEntry.Name        = device.Name;
                        dbEntry.TypeId      = device.TypeId;
                        dbEntry.Statistics  = device.Statistics;
                        dbEntry.UserId      = device.UserId;
                        dbEntry.Description = device.Description;
                    }
                }

                Context.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                // Obsługa błędów EF
                using (var handler = new DbValidationErrorHandler(ex))
                {
                    if (handler.HasErrors)
                    {
                        response.Errors.AddRange(handler.ValidationErrors);
                    }
                }
            }
            catch (Exception ex)
            {
                var hierarchy = new List <Exception>();
                ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy);
                if (hierarchy.Count > 0)
                {
                    response.Errors.AddRange(hierarchy.Select(s => new ApiValidationErrorItem {
                        Message = s.Message
                    }).Distinct().AsEnumerable());
                }
            }

            response.Accepted = response.Errors.Count == 0;
            return(response);
        }
Example #2
0
        /// <summary>
        /// Zapisywanie typu do bazy danych
        /// </summary>
        /// <param name="type">Obiekt typu</param>
        public ApiResponse Save(Models.Type type)
        {
            var response = new ApiResponse();

            try
            {
                if (type.Id == 0)
                {
                    Context.Types.Add(type);
                }
                else
                {
                    var dbEntry = Context.Types.Find(type.Id);
                    if (dbEntry != null)
                    {
                        dbEntry.Name   = type.Name;
                        dbEntry.Height = type.Height;
                        dbEntry.Width  = type.Width;
                    }
                }

                Context.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                //  Obsługa błędów EF
                using (var handler = new DbValidationErrorHandler(ex))
                {
                    if (handler.HasErrors)
                    {
                        response.Errors.AddRange(handler.ValidationErrors);
                    }
                }
            }
            catch (Exception ex)
            {
                var hierarchy = new List <Exception>();
                ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy);
                if (hierarchy.Count > 0)
                {
                    response.Errors.AddRange(hierarchy.Select(s => new ApiValidationErrorItem {
                        Message = s.Message
                    }).Distinct().AsEnumerable());
                }
            }

            response.Accepted = response.Errors.Count == 0;
            return(response);
        }
 /// <summary>
 /// Pobranie informacji o błędach bazodanowych na podstawie stanu modelu
 /// </summary>
 /// <param name="ex">Wyjątek</param>
 /// <param name="ModelState">Stan modelu</param>
 /// <param name="prefix">Prefiks określający nazwę właściwości modelu dla której sprawdzane są błędy</param>
 public static void ModelHandleException(Exception ex, System.Web.Mvc.ModelStateDictionary ModelState, string prefix)
 {
     if (ex is System.Data.Entity.Validation.DbEntityValidationException)
     {
         using (DbValidationErrorHandler dvValExp = new DbValidationErrorHandler(ex as System.Data.Entity.Validation.DbEntityValidationException))
         {
             if (dvValExp.HasErrors)
             {
                 foreach (var err in dvValExp.ValidationErrors)
                 {
                     ModelState.AddModelError(prefix + "." + err.Property, err.Message);
                 }
             }
         }
     }
     else
     {
         ModelState.AddModelError("", ex.Message);
     }
 }
Example #4
0
        public ApiResponse Save(Entities.StatisticsEntry statisticsEntry)
        {
            var response = new ApiResponse();

            statisticsEntry.Statistics.Name = "Stats";
            using (var transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    var dbEntry = new Statistic();
                    dbEntry.Name = "Stats";

                    #region zapis danych podstawowych statystyk

                    if (statisticsEntry.Statistics.Id == 0)
                    {
                        dbEntry.Data1 = statisticsEntry.Statistics.Data1 ?? "";
                        dbEntry.MultimediaObjectId = statisticsEntry.Statistics.MultimediaObjectId;
                        dbEntry.Data2         = statisticsEntry.Statistics.Data2 ?? "";
                        dbEntry.Data3         = statisticsEntry.Statistics.Data3 ?? "";
                        dbEntry.Data4         = "";
                        dbEntry.RequestDate   = statisticsEntry.Statistics.RequestDate;
                        dbEntry.RequestIP     = statisticsEntry.Statistics.RequestIP;
                        dbEntry.RequestSource = statisticsEntry.Statistics.RequestSource;
                        statisticsEntry.Statistics.ResponseDate = DateTime.Now;
                        dbEntry.ResponseDate = statisticsEntry.Statistics.ResponseDate;
                        dbEntry.SessionId    = statisticsEntry.Statistics.SessionId;
                        dbEntry.Clicked      = statisticsEntry.Statistics.Clicked;
                        dbEntry.AdPoints     = statisticsEntry.Statistics.AdPoints;
                        dbEntry.DeviceId     = statisticsEntry.Statistics.DeviceId;
                        dbEntry.UserId       = statisticsEntry.Statistics.UserId;
                        dbEntry.CampaignId   = statisticsEntry.Statistics.CampaignId;
                        Context.Statistics.Add(dbEntry);
                        Context.SaveChanges();
                    }

                    #endregion zapis danych podstawowych statystyk

                    #region zapis powiązań statystyki z kampaniami

                    //foreach (var cp in statisticsEntry.SelectedMultimediaObjectCampaigns)
                    //{
                    //	//Context.Statistics_Campaign.Add(new Statistics_Campaign
                    //	//{
                    //	//	CampaignId = cp.CampaignId,
                    //	//	StatisticsId = dbEntry.Id
                    //	//});
                    //	//Context.SaveChanges();
                    //}

                    #endregion zapis powiązań statystyki z kampaniami

                    #region zapis powiązań statystyki z kategoriami

                    foreach (var cp in statisticsEntry.Categories)
                    {
                        //Context.Statistics_Category.Add(new Statistics_Category
                        //{
                        //	CategoryId = cp.Value,
                        //	StatisticsId = dbEntry.Id
                        //});
                        //Context.SaveChanges();
                    }

                    #endregion zapis powiązań statystyki z kategoriami

                    transaction.Commit();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    // Obsługa błędów EF
                    using (var handler = new DbValidationErrorHandler(ex))
                    {
                        if (handler.HasErrors)
                        {
                            response.Errors.AddRange(handler.ValidationErrors);
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Obsługa błędów pozostałych
                    var hierarchy = new List <Exception>();
                    ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy);
                    if (hierarchy.Count > 0)
                    {
                        response.Errors.AddRange(
                            hierarchy.Select(s => new ApiValidationErrorItem {
                            Message = s.Message + Environment.NewLine + s.StackTrace
                        })
                            .Distinct()
                            .AsEnumerable());
                    }
                }

                if (response.Errors.Count > 0)
                {
                    transaction.Rollback();
                }

                response.Accepted = response.Errors.Count == 0;
                return(response);
            }
        }
Example #5
0
        /// <summary>
        /// Zapisywanie/Modyfikacja użytkownika
        /// </summary>
        /// <param name="user">Użytkownik</param>
        /// <returns>Odpowiedź funkcji</returns>
        public ApiResponse Save(User user)
        {
            var response = new ApiResponse {
                Errors = new List <ApiValidationErrorItem>()
            };

            #region Errors

            if (user.RoleId == 0)
            {
                response.Errors.Add(new ApiValidationErrorItem {
                    Property = "Role", Message = "Nieprawidłowe uprawnienia użytkownika"
                });
                response.Accepted = false;
                return(response);
            }

            #endregion Errors

            using (var transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    User dbEntry;

                    #region Zapis danych podstawowych kampanii

                    if (user.Id > 0)
                    {
                        dbEntry = Context.Users.FirstOrDefault(f => f.Id == user.Id);
                        if (dbEntry != null)
                        {
                            if (!string.IsNullOrEmpty(user.Name))
                            {
                                dbEntry.Name = user.Name;
                            }
                            if (!string.IsNullOrEmpty(user.LastName))
                            {
                                dbEntry.LastName = user.LastName;
                            }
                            if (!string.IsNullOrEmpty(user.FirstName))
                            {
                                dbEntry.FirstName = user.FirstName;
                            }
                            if (!string.IsNullOrEmpty(user.Password))
                            {
                                dbEntry.Password = user.Password;
                            }
                            if (user.CompanyAddress != null)
                            {
                                dbEntry.CompanyAddress = user.CompanyAddress;
                            }
                            if (user.CompanyName != null)
                            {
                                dbEntry.CompanyName = user.CompanyName;
                            }
                            if (user.AdditionalInfo != null)
                            {
                                dbEntry.AdditionalInfo = user.AdditionalInfo;
                            }
                            if (!string.IsNullOrEmpty(user.Email))
                            {
                                dbEntry.Email = user.Email;
                            }
                            if (!string.IsNullOrEmpty(user.Url))
                            {
                                dbEntry.Url = user.Url;
                            }
                            dbEntry.RoleId    = user.RoleId;
                            dbEntry.AdPoints  = user.AdPoints;
                            dbEntry.IsBlocked = user.IsBlocked;
                            Context.SaveChanges();
                        }
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(user.Name))
                        {
                            response.Errors.Add(new ApiValidationErrorItem {
                                Property = "Name", Message = "Nieprawidłowe dane"
                            });
                            response.Accepted = false;
                            return(response);
                        }
                        dbEntry = new User
                        {
                            Name           = user.Name,
                            LastName       = user.LastName,
                            FirstName      = user.FirstName,
                            Password       = user.Password,
                            Email          = user.Email,
                            AdditionalInfo = user.AdditionalInfo,
                            CompanyName    = user.CompanyName,
                            CompanyAddress = user.CompanyAddress,
                            Url            = user.Url,
                            IsBlocked      = user.IsBlocked,
                            RoleId         = user.RoleId,
                            AdPoints       = user.AdPoints
                        };
                        Context.Users.Add(dbEntry);
                        Context.SaveChanges();

                        var device    = new Device();
                        var devRepo   = new EFDeviceRepository();
                        var imageRepo = new EFMultimediaObjectRepository();
                        var u         = Context.Campaigns.FirstOrDefault(it => it.Name == "LogoEC2" && it.User.Role.Name == "Admin");

                        device.Name        = "LogoEC2";
                        device.Description = "Przykładowa kampania AdServera";
                        device.TypeId      = (int)u.MultimediaObjects.First().TypeId;
                        device.UserId      = dbEntry.Id;

                        var camps = new List <Campaign>();
                        var cats  = new List <Category>();
                        camps.Add(u);
                        cats.AddRange(u.Categories);

                        device.Campaigns.Add(u);
                        //device.Categories = u.Categories;
                        devRepo.Save(device);
                        dbEntry.Devices = new Collection <Device> {
                            device
                        };
                        Context.SaveChanges();
                    }

                    #endregion Zapis danych podstawowych kampanii

                    transaction.Commit();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    // Obsługa błędów EF
                    using (var handler = new DbValidationErrorHandler(ex))
                    {
                        if (handler.HasErrors)
                        {
                            response.Errors.AddRange(handler.ValidationErrors);
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Obsługa błędów pozostałych
                    var hierarchy = new List <Exception>();
                    ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy);
                    if (hierarchy.Count > 0)
                    {
                        response.Errors.AddRange(hierarchy.Select(s => new ApiValidationErrorItem {
                            Message = s.Message + Environment.NewLine + s.StackTrace
                        }).Distinct().AsEnumerable());
                    }
                }

                if (response.Errors.Count > 0)
                {
                    transaction.Rollback();
                }
            }

            response.Accepted = response.Errors.Count == 0;
            return(response);
        }
Example #6
0
        /// <summary>
        /// Zapisuje obiekt multimedialny do bazy
        /// </summary>
        /// <param name="multimediaObject">Obiekt multimedialny</param>
        public ApiResponse Save(MultimediaObject multimediaObject, List <Campaign> Camps)
        {
            var response = new ApiResponse();

            if (!string.IsNullOrEmpty(multimediaObject.FileContent))
            {
                var index = multimediaObject.FileContent.IndexOf("base64,");
                if (index != -1)
                {
                    multimediaObject.FileContent = multimediaObject.FileContent.Substring(index + "base64,".Length);
                }
                if (multimediaObject.Url == null)
                {
                    throw new Exception("Nie ustawiono adres URL dla obiektu!");
                }

                using (var transaction = Context.Database.BeginTransaction())
                {
                    try
                    {
                        dynamic dbEntry;
                        var     multimediaObjectType = Context.Types.FirstOrDefault(x => x.Id == multimediaObject.TypeId);
                        if (multimediaObjectType == null)
                        {
                            throw new Exception("Nie znaleziono wskazanego typu obiektu. Możliwe zmiany na innym stanowisku.");
                        }

                        // Konwersja formatu base64 na tablicę bajtów
                        var imageBytes = Convert.FromBase64String(multimediaObject.FileContent);

                        byte[] thumbnail = imageBytes;

                        #region Zapis danych podstawowych obiektu
                        if (multimediaObject.Id > 0)
                        {
                            dbEntry = Context.MultimediaObjects.SingleOrDefault(f => f.Id == multimediaObject.Id);
                            if (dbEntry != null)
                            {
                                dbEntry.UserId = multimediaObject.UserId;

                                dbEntry.FileName  = multimediaObject.FileName;
                                dbEntry.MimeType  = multimediaObject.MimeType;
                                dbEntry.Name      = multimediaObject.Name;
                                dbEntry.TypeId    = multimediaObject.TypeId;
                                dbEntry.Url       = multimediaObject.Url;
                                dbEntry.Contents  = imageBytes;
                                dbEntry.Thumbnail = thumbnail;

                                SetRelation(multimediaObject, ref dbEntry);
                                Context.SaveChanges();
                            }
                        }
                        else
                        {
                            ICollection <Campaign> CampList = new List <Campaign>();
                            foreach (var camp in Camps)
                            {
                                Campaign c = Context.Campaigns.FirstOrDefault(p => p.Id == camp.Id);
                                Context.Campaigns.Attach(c);
                                CampList.Add(c);
                            }

                            dbEntry = new MultimediaObject
                            {
                                FileName  = multimediaObject.FileName,
                                MimeType  = multimediaObject.MimeType,
                                Name      = multimediaObject.Name,
                                TypeId    = multimediaObject.TypeId,
                                Url       = multimediaObject.Url,
                                Contents  = imageBytes,
                                Thumbnail = thumbnail,
                                UserId    = multimediaObject.UserId,
                                Campaigns = CampList,
                                Content   = multimediaObject.Contents,
                            };

                            SetRelation(multimediaObject, ref dbEntry);

                            Context.MultimediaObjects.Add(dbEntry);
                            Context.SaveChanges();
                        }
                        #endregion


                        transaction.Commit();
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                    {
                        // Obsługa błędów EF
                        using (var handler = new DbValidationErrorHandler(ex))
                        {
                            if (handler.HasErrors)
                            {
                                response.Errors.AddRange(handler.ValidationErrors);
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        // Obsługa błędów pozostałych
                        var hierarchy = new List <Exception>();
                        ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy);
                        if (hierarchy.Count > 0)
                        {
                            response.Errors.AddRange(hierarchy.Select(s => new ApiValidationErrorItem {
                                Message = s.Message + Environment.NewLine + s.StackTrace
                            }).Distinct().AsEnumerable());
                        }
                    }

                    if (response.Errors.Count > 0)
                    {
                        transaction.Rollback();
                    }
                }
            }
            else
            {
                response.Errors.Add(new ApiValidationErrorItem {
                    Message = "Należy dołączyć plik multimedialny."
                });
            }

            response.Accepted = response.Errors.Count == 0;
            return(response);
        }
Example #7
0
        /// <summary>
        /// Zapisuje kategorię do bazy danych
        /// </summary>
        /// <param name="category">Obiekt kategorii do zapisu</param>
        public ApiResponse Save(Category category)
        {
            var response = new ApiResponse();

            using (var transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    dynamic dbEntry;

                    if (category.Id > 0)
                    {
                        dbEntry = Context.Categories.FirstOrDefault(f => f.Id == category.Id);
                        if (dbEntry != null)
                        {
                            dbEntry.Name = category.Name;
                            dbEntry.Code = category.Code;
                            SetRelation(category, ref dbEntry);
                            Context.SaveChanges();
                        }
                    }
                    else
                    {
                        dbEntry = new Category
                        {
                            Name = category.Name,
                            Code = category.Code
                        };
                        SetRelation(category, ref dbEntry);
                        Context.Categories.Add(dbEntry);
                        Context.SaveChanges();
                    }

                    transaction.Commit();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    //  Obsługa błędów EF
                    using (var handler = new DbValidationErrorHandler(ex))
                    {
                        if (handler.HasErrors)
                        {
                            response.Errors.AddRange(handler.ValidationErrors);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //  Obsługa błędów pozostałych
                    var hierarchy = new List <Exception>();
                    ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy);
                    if (hierarchy.Count > 0)
                    {
                        response.Errors.AddRange(hierarchy.Select(s => new ApiValidationErrorItem {
                            Message = s.Message + Environment.NewLine + s.StackTrace
                        }).Distinct().AsEnumerable());
                    }
                }

                if (response.Errors.Count > 0)
                {
                    transaction.Rollback();
                }
            }
            response.Accepted = response.Errors.Count == 0;
            return(response);
        }
Example #8
0
        /// <summary>
        /// Zapisuje kampanię do bazy danych
        /// </summary>
        /// <param name="campaign">Obiekt kampanii do zapisu</param>
        /// <param name="decrement">Czy tylko zmniejszanie</param>
        public ApiResponse SaveCampaign(Campaign campaign, bool decrement = false)
        {
            var response = new ApiResponse();

            if (campaign.StartDate == DateTime.MinValue || campaign.StartDate == DateTime.MaxValue)
            {
                response.Errors = new List <ApiValidationErrorItem>
                {
                    new ApiValidationErrorItem
                    {
                        Property = "StartDate",
                        Message  = "Niepoprawna data"
                    }
                };
                response.Accepted = false;
                return(response);
            }

            if (campaign.EndDate == DateTime.MinValue || campaign.StartDate == DateTime.MaxValue)
            {
                response.Errors = new List <ApiValidationErrorItem>
                {
                    new ApiValidationErrorItem
                    {
                        Property = "EndDate",
                        Message  = "Niepoprawna data"
                    }
                };
                response.Accepted = false;
                return(response);
            }

            if (campaign.StartDate.Date > campaign.EndDate.Date)
            {
                response.Errors = new List <ApiValidationErrorItem>
                {
                    new ApiValidationErrorItem
                    {
                        Property = "StartDate",
                        Message  = "Data rozpoczęcia musi być wcześniejsza od daty zakończenia."
                    }
                };
                response.Accepted = false;
                return(response);
            }
            using (var transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    dynamic dbEntry;

                    if (campaign.Id > 0)
                    {
                        dbEntry = Context.Campaigns.FirstOrDefault(f => f.Id == campaign.Id);

                        if (dbEntry != new Campaign())
                        {
                            if (dbEntry == null)
                            {
                                response.Errors = new List <ApiValidationErrorItem>
                                {
                                    new ApiValidationErrorItem
                                    {
                                        Property = "Id",
                                        Message  = "Brak kampanii"
                                    }
                                };
                                response.Accepted = false;
                                return(response);
                            }
                            dbEntry.UserId      = campaign.UserId;
                            dbEntry.Description = campaign.Description;
                            dbEntry.EndDate     = campaign.EndDate;
                            dbEntry.IsActive    = campaign.IsActive;
                            dbEntry.Name        = campaign.Name;
                            dbEntry.PriorityId  = campaign.PriorityId;
                            dbEntry.StartDate   = campaign.StartDate;
                            dbEntry.ViewValue   = campaign.ViewValue;
                            dbEntry.ClickValue  = campaign.ClickValue;
                            if (!decrement)
                            {
                                SetRelation(campaign, ref dbEntry);
                            }

                            var duser = Context.Users.First(it => it.Id == campaign.UserId);

                            if (!decrement)
                            {
                                if (dbEntry.AdPoints != campaign.AdPoints && ((dbEntry.AdPoints - campaign.AdPoints) > duser.AdPoints || campaign.AdPoints < 0))
                                {
                                    response.Errors = new List <ApiValidationErrorItem>
                                    {
                                        new ApiValidationErrorItem
                                        {
                                            Property = "AdPoints",
                                            Message  = "Nierawidłowa ilość punktów na kamapanie"
                                        }
                                    };
                                    response.Accepted = false;
                                    return(response);
                                }

                                if (dbEntry.AdPoints != campaign.AdPoints && !(dbEntry.AdPoints - campaign.AdPoints > duser.AdPoints || campaign.AdPoints < 0))
                                {
                                    duser.AdPoints += dbEntry.AdPoints - campaign.AdPoints;
                                }
                            }
                            dbEntry.AdPoints = campaign.AdPoints < 0 ? 0 : campaign.AdPoints;

                            Context.SaveChanges();
                        }
                    }
                    else
                    {
                        dbEntry = new Campaign
                        {
                            Description = campaign.Description,
                            EndDate     = campaign.EndDate,
                            IsActive    = campaign.IsActive,
                            Name        = campaign.Name,
                            PriorityId  = campaign.PriorityId,
                            StartDate   = campaign.StartDate,
                            UserId      = campaign.UserId ?? 0,
                            AdPoints    = campaign.AdPoints,
                            ViewValue   = campaign.ViewValue,
                            ClickValue  = campaign.ClickValue
                        };

                        var dbUser = Context.Users.First(it => it.Id == campaign.UserId);
                        if (dbEntry.AdPoints != campaign.AdPoints)
                        {
                            dbUser.AdPoints -= campaign.AdPoints;
                        }

                        if (dbEntry.AdPoints != campaign.AdPoints || (campaign.AdPoints > dbUser.AdPoints || campaign.AdPoints < 0))
                        {
                            response.Errors = new List <ApiValidationErrorItem>
                            {
                                new ApiValidationErrorItem
                                {
                                    Property = "AdPoints",
                                    Message  = "Nierawidłowa ilość punktów na kamapanie"
                                }
                            };
                            response.Accepted = false;
                            return(response);
                        }

                        SetRelation(campaign, ref dbEntry);

                        Context.Campaigns.Add(dbEntry);
                        Context.SaveChanges();
                    }

                    transaction.Commit();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    // Obsługa błędów EF
                    using (var handler = new DbValidationErrorHandler(ex))
                    {
                        if (handler.HasErrors)
                        {
                            response.Errors.AddRange(handler.ValidationErrors);
                        }
                    }
                }

                catch (Exception ex)
                {
                    // Obsługa błędów pozostałych
                    var hierarchy = new List <Exception>();
                    ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy);
                    if (hierarchy.Count > 0)
                    {
                        response.Errors.AddRange(hierarchy.Select(s => new ApiValidationErrorItem {
                            Message = s.Message + Environment.NewLine + s.StackTrace
                        }).Distinct().AsEnumerable());
                    }
                }

                if (response.Errors.Count > 0)
                {
                    transaction.Rollback();
                }
            }

            response.Accepted = response.Errors.Count == 0;
            return(response);
        }