public async System.Threading.Tasks.Task <OperationResult <Company> > DeleteCompany(int id)
 {
     return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <Company> >(() =>
     {
         OperationResult <Company> result = new OperationResult <Company>();
         try
         {
             if (IsInCompany(id))
             {
                 Company company = CompaniesRepository.Read(id);
                 if (company != null)
                 {
                     if (company.OwnerId == CurrentUser.Id)
                     {
                         result.Result = CompaniesRepository.Delete(id);
                         if (result.Result)
                         {
                             UserStore.RemoveFromRoleAsync(CurrentUser, RoleNames.CompanyOwner);
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             LoggingService.Log(ex);
         }
         return result;
     }));
 }
Ejemplo n.º 2
0
        public async System.Threading.Tasks.Task <OperationResult <OrderResponse> > GetCompanyForOrder(int id)
        {
            return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <OrderResponse> >(() =>
            {
                OperationResult <OrderResponse> result = new OperationResult <OrderResponse>();
                try
                {
                    var company = CompaniesRepository.Read(id);
                    if (company != null)
                    {
                        company.OwnerId = Guid.Empty;
                        company.Description = "";
                        company.LogoImage = "";
                        var playgrounds = PlaygroundsRepository.Search("CompanyId = @CompanyId",
                                                                       new { PageNumber = 1, PageSize = 100, CompanyId = company.Id });

                        var gameTypes = GameTypesRepository.Search("CompanyId = @CompanyId",
                                                                   new { PageNumber = 1, PageSize = 100, CompanyId = company.Id });

                        var equipment = EquipmentsRepository.Search("CompanyId = @CompanyId",
                                                                    new { PageNumber = 1, PageSize = 100, CompanyId = company.Id });
                        foreach (var equip in equipment)
                        {
                            equip.State = "";
                        }

                        result.SingleResult = new OrderResponse
                        {
                            Company = company,
                            Playgrounds = playgrounds,
                            GameTypes = gameTypes,
                            Equipment = equipment
                        };
                        result.Result = true;
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
                return result;
            }));
        }
 public async System.Threading.Tasks.Task <OperationResult <Company> > ReadCompany(int id)
 {
     return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <Company> >(() =>
     {
         OperationResult <Company> result = new OperationResult <Company>();
         try
         {
             Company company = CompaniesRepository.Read(id);
             if (company != null)
             {
                 result.SingleResult = company;
                 result.Result = true;
             }
         }
         catch (Exception ex)
         {
             LoggingService.Log(ex);
         }
         return result;
     }));
 }