Exemple #1
0
        public async Task <IActionResult> DeleteProductAsync(int productId, string userId)
        {
            try
            {
                if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, userId, "Modyfikacja produktów")))
                {
                    return(new JsonResult(new ApiResponse <object>
                    {
                        Data = null,
                        Code = 403,
                        ErrorMessage = "Brak uprawnień"
                    }));
                }
                await _productRepository.DeleteProductAsync(productId);

                return(new JsonResult(new ApiResponse <object>
                {
                    Code = 200,
                    Data = null,
                    ErrorMessage = ""
                }));
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Code = 500,
                    Data = null,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
Exemple #2
0
        public async Task <IActionResult> AddProductAsync(ProductUpsertDto product, string userId)
        {
            try
            {
                if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, userId, "Modyfikacja produktów")))
                {
                    return(new JsonResult(new ApiResponse <object>
                    {
                        Data = null,
                        Code = 403,
                        ErrorMessage = "Brak uprawnień"
                    }));
                }
                var validator = new ProductValidator();
                var result    = validator.Validate(product);

                if (result.IsValid)
                {
                    var productToDB = _mapper.Map <ApiDomain.Entity.Product>(product);
                    return(new JsonResult(new ApiResponse <ProductUpsertDto>()
                    {
                        Code = 201,
                        ErrorMessage = "",
                        Data = _mapper.Map <ProductUpsertDto>(await _productRepository.AddProductAsync(productToDB))
                    }));
                }
                else
                {
                    var errorMsg = "";

                    foreach (var err in result.Errors)
                    {
                        errorMsg += err.ErrorMessage + "\r\n";
                    }

                    return(new JsonResult(new ApiResponse <ProductUpsertDto>()
                    {
                        Code = 406,
                        ErrorMessage = errorMsg,
                        Data = null
                    }));
                }
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Code = 500,
                    Data = null,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
Exemple #3
0
        public async Task <IActionResult> EditProductAsync(ProductUpsertDto product, string userId)
        {
            try
            {
                if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, userId, "Modyfikacja produktów")))
                {
                    return(new JsonResult(new ApiResponse <object>
                    {
                        Data = null,
                        Code = 403,
                        ErrorMessage = "Brak uprawnień"
                    }));
                }

                ApiDomain.Entity.Product DBProduct = await _productRepository.GetProductByIdAsync(product.Id);

                if (DBProduct != null)
                {
                    DBProduct.MarkupRate = product.MarkupRate;
                    DBProduct.Name       = product.Name;
                    DBProduct.UnitValue  = product.UnitValue;
                    DBProduct.VatRate    = product.VatRate;
                    await _productRepository.EditProductAsync(DBProduct);

                    return(new JsonResult(new ApiResponse <object>
                    {
                        Code = 200,
                        Data = null,
                        ErrorMessage = ""
                    }));
                }
                else
                {
                    return(new JsonResult(new ApiResponse <object>
                    {
                        Code = 404,
                        Data = null,
                        ErrorMessage = "Produkt nie odnaleziony."
                    }));
                }
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Code = 500,
                    Data = null,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
Exemple #4
0
        public async Task <IActionResult> GetAllProductsAsync(int companyId, ProductFiltersDto dto, string userId)
        {
            try
            {
                if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, userId, "Przeglądanie produktów")))
                {
                    return(new JsonResult(new ApiResponse <object>
                    {
                        Data = null,
                        Code = 403,
                        ErrorMessage = "Brak uprawnień"
                    }));
                }
                var filterList = new List <string>
                {
                    dto.Name,
                    dto.VatRate.Replace("%", ""),
                    dto.MarkupRate.Replace("%", "")
                };
                var products = _mapper.Map <List <ProductForListDto> >(await _productRepository.GetAllProductsAsync(companyId, filterList));

                return(new JsonResult(new ApiResponse <List <ProductForListDto> >
                {
                    Code = 200,
                    Data = products,
                    ErrorMessage = ""
                }));
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Code = 500,
                    Data = null,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
Exemple #5
0
        public async Task <IActionResult> Handle(GetAdministrationDataQuery request, CancellationToken cancellationToken)
        {
            try
            {
                if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, request.UserId, "Panel administracji")))
                {
                    return(new JsonResult(new ApiResponse <object>
                    {
                        Data = null,
                        Code = 403,
                        ErrorMessage = "Brak uprawnień"
                    }));
                }

                var users = await _userRepository.GetCompanyTraders(request.CompanyId);

                var administrationData = new AdministrationDataDto
                {
                    Users      = new List <UserForAdministrationDto>(),
                    Statistics = new CompanyStatisticsDto
                    {
                        Activities      = new List <int>(),
                        Opportunities   = new List <int>(),
                        ThisMonthGross  = 0,
                        ThisMonthMarkup = 0,
                        ThisMonthNet    = 0,
                        ThisYearGross   = 0,
                        ThisYearMarkup  = 0,
                        ThisYearNet     = 0
                    },
                };

                var company = await _companyRepository.GetByIdAsync(request.CompanyId);

                administrationData.Company = new CompanyDataDto
                {
                    Address = new AddressDto
                    {
                        ApartmentNumber = company.Address.ApartmentNumber,
                        City            = company.Address.City,
                        HouseNumber     = company.Address.HouseNumber,
                        Id       = company.Address.Id,
                        PostCode = company.Address.PostCode,
                        Province = company.Address.Province,
                        Street   = company.Address.Street
                    },
                    Id    = company.Id,
                    Name  = company.CompanyName,
                    Nip   = company.NIP,
                    Regon = company.Regon
                };

                var oppos = await _opportunityRepository.GetAllOpportunitiesAsync(request.CompanyId, new List <string> {
                    "", "", ""
                }, new DateTime(DateTime.Now.Year - 1, 1, 1), new DateTime(DateTime.Now.Year, 12, 31));

                oppos.AddRange(await _opportunityRepository.GetAllOrdersAsync(request.CompanyId, new List <string> {
                    "", ""
                }, new DateTime(DateTime.Now.Year - 1, 1, 1), new DateTime(DateTime.Now.Year, 12, 31)));

                foreach (var oppo in oppos)
                {
                    administrationData.Statistics.ThisYearGross  += oppo.SumGrossValue;
                    administrationData.Statistics.ThisYearMarkup += oppo.SumMarkupValue;
                    administrationData.Statistics.ThisYearNet    += oppo.SumNetValue;

                    if (oppo.CreateDate.Month == DateTime.Now.Month)
                    {
                        administrationData.Statistics.ThisMonthGross  += oppo.SumGrossValue;
                        administrationData.Statistics.ThisMonthMarkup += oppo.SumMarkupValue;
                        administrationData.Statistics.ThisMonthNet    += oppo.SumNetValue;
                    }
                }

                var oppoStatuses = new List <string>
                {
                    "Nowa",
                    "Modyfikowana",
                    "Anulowana",
                    "Zaakceptowana",
                    "Oferta"
                };

                foreach (var oppoStat in oppoStatuses)
                {
                    administrationData.Statistics.Opportunities.Add(oppos.Where(x => x.Status.Name == oppoStat).Count());
                }

                foreach (var user in users)
                {
                    administrationData.Users.Add(new UserForAdministrationDto
                    {
                        Id         = user.Id,
                        CanDelete  = (user.Id != request.UserId),
                        Department = user.CompanyPosition,
                        Name       = user.FirstName + " " + user.LastName,
                        StartDate  = user.WorkStartDate.ToString("dd.MM.yyyy"),
                        Gender     = user.Gender
                    });
                }

                var activities = await _activityTypeRepository.GetActivityTypesAsync();

                var leads = await _leadRepository.GetAllLeadsAsync(request.CompanyId, new DateTime(DateTime.Now.Year, 1, 1), new DateTime(DateTime.Now.Year, 12, 31));

                foreach (var activity in activities)
                {
                    administrationData.Statistics.Activities.Add(0);
                }

                foreach (var lead in leads)
                {
                    int counter = 0;
                    foreach (var activity in activities)
                    {
                        administrationData.Statistics.Activities[counter] += lead.Activities.Where(x => x.ActivityType == activity).Count();
                        counter += 1;
                    }
                }

                return(new JsonResult(new ApiResponse <AdministrationDataDto>
                {
                    Code = 200,
                    Data = administrationData,
                    ErrorMessage = ""
                }));
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Code = 500,
                    Data = null,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
Exemple #6
0
        public async Task <IActionResult> Handle(GetAllLeadsQuery request, CancellationToken cancellationToken)
        {
            try
            {
                if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, request.UserId, "Przeglądanie leadów")))
                {
                    return(new JsonResult(new ApiResponse <object>
                    {
                        Data = null,
                        Code = 403,
                        ErrorMessage = "Brak uprawnień"
                    }));
                }

                var dbLeads = await _leadRepository.GetAllLeadsAsync(request.CompanyId, request.Filters.DateFrom, request.Filters.DateTo);

                var traders = await _userRepository.GetCompanyTraders(request.CompanyId);

                var response = new LeadListResponseDto()
                {
                    CompanyTraders = new List <string>(),
                    Leads          = new List <LeadForListDto>()
                };

                foreach (var trader in traders)
                {
                    response.CompanyTraders.Add(trader.FirstName + " " + trader.LastName);
                }

                foreach (var lead in dbLeads)
                {
                    response.Leads.Add(new LeadForListDto
                    {
                        Id          = lead.Id,
                        Email       = lead.LeadContacts.Count > 0?lead.LeadContacts.First().Email:"",
                        User        = lead.User.FirstName + " " + lead.User.LastName,
                        MainContact = lead.LeadContacts.Count > 0 ? lead.LeadContacts.First().Name:"",
                        Name        = lead.Name,
                        CreateDate  = lead.CreateDate,
                        Status      = lead.LeadStatus.Name
                    });
                }

                if (request.Filters.Name != "")
                {
                    response.Leads = response.Leads.Where(x => x.Name.Contains(request.Filters.Name)).ToList();
                }
                if (request.Filters.Status != "")
                {
                    response.Leads = response.Leads.Where(x => x.Status == request.Filters.Status).ToList();
                }
                if (request.Filters.User != "")
                {
                    response.Leads = response.Leads.Where(x => x.User.Contains(request.Filters.User)).ToList();
                }
                if (request.Filters.Email != "")
                {
                    response.Leads = response.Leads.Where(x => x.Email.Contains(request.Filters.Email)).ToList();
                }

                return(new JsonResult(new ApiResponse <LeadListResponseDto>
                {
                    Data = response,
                    Code = 200,
                    ErrorMessage = ""
                }));
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Data = null,
                    Code = 500,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
        public async Task <IActionResult> Handle(GetAllOpportunitiesQuery request, CancellationToken cancellationToken)
        {
            try
            {
                if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, request.UserId, "Modyfikacja cudzych szans sprzedaży")))
                {
                    return(new JsonResult(new ApiResponse <object>
                    {
                        Data = null,
                        Code = 403,
                        ErrorMessage = "Brak uprawnień"
                    }));
                }
                var traders = await _userRepository.GetCompanyTraders(request.CompanyId);

                var opportunities = new List <SellOpportunityHeader>();

                if (request.GetOrders)
                {
                    opportunities = await _opportunityRepostitory.GetAllOrdersAsync(request.CompanyId, new List <string>
                    {
                        request.Filters.LeadName,
                        request.Filters.Trader
                    }, request.Filters.DateFrom, request.Filters.DateTo);
                }
                else
                {
                    opportunities = await _opportunityRepostitory.GetAllOpportunitiesAsync(request.CompanyId, new List <string>
                    {
                        request.Filters.Status,
                        request.Filters.LeadName,
                        request.Filters.Trader
                    }, request.Filters.DateFrom, request.Filters.DateTo);
                }

                var response = new SellOpportunityListDto
                {
                    SellOpportunities = new List <SellOpportunityForListDto>(),
                    TraderList        = new List <string>()
                };

                foreach (var trader in traders)
                {
                    response.TraderList.Add(trader.FirstName + " " + trader.LastName);
                }

                foreach (var oppo in opportunities)
                {
                    var oppoDto = new SellOpportunityForListDto
                    {
                        Id             = oppo.Id,
                        Lead           = oppo.Lead.Name,
                        Positions      = new List <SellOpportunityPositionForListDto>(),
                        Status         = oppo.Status.Name,
                        SumGrossValue  = oppo.SumGrossValue,
                        SumMarkupValue = oppo.SumMarkupValue,
                        SumNetValue    = oppo.SumNetValue,
                        SumVatValue    = oppo.SumVatValue,
                        Trader         = oppo.Trader.FirstName + " " + oppo.Trader.LastName,
                        CreateDate     = oppo.CreateDate
                    };

                    foreach (var oppoPos in oppo.Positions)
                    {
                        oppoDto.Positions.Add(new SellOpportunityPositionForListDto
                        {
                            GrossValue = oppoPos.GrossValue,
                            Id         = oppoPos.Id,
                            Markup     = oppoPos.Markup,
                            NetValue   = oppoPos.NetValue,
                            Product    = oppoPos.Product.Name,
                            Quantity   = oppoPos.Quantity,
                            VatValue   = oppoPos.VatValue
                        });
                    }

                    response.SellOpportunities.Add(oppoDto);
                }

                return(new JsonResult(new ApiResponse <SellOpportunityListDto>
                {
                    Code = 200,
                    Data = response,
                    ErrorMessage = ""
                }));
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Data = null,
                    Code = 500,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
Exemple #8
0
        public async Task <IActionResult> Handle(GetOpportunityQuery request, CancellationToken cancellationToken)
        {
            try
            {
                var tradersList = await _userRepository.GetCompanyTraders(request.CompanyId);

                var products = await _productRepository.GetAllProductsAsync(request.CompanyId, new List <string> {
                    "", "", ""
                });

                var leads = await _leadRepository.GetAllLeadsAsync(request.CompanyId, new DateTime(2000, 01, 01), new DateTime(2999, 12, 31));

                var opportunity = await _opportunityRepository.GetOpportunityAsync(request.OpportunityId, request.CompanyId);

                if (opportunity != null && opportunity.TraderId != request.UserId)
                {
                    if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, request.UserId, "Modyfikacja cudzych szans sprzedaży")))
                    {
                        return(new JsonResult(new ApiResponse <object>
                        {
                            Data = null,
                            Code = 403,
                            ErrorMessage = "Brak uprawnień"
                        }));
                    }
                }

                var oppoRes = new SellOpportunityDetailsDto();

                if (request.OpportunityId > 0)
                {
                    oppoRes = new SellOpportunityDetailsDto
                    {
                        Id        = opportunity.Id,
                        Lead      = opportunity.Lead.Name + "," + opportunity.Lead.NIP,
                        Positions = new List <SellOpportunityPositionDetailsDto>(),
                        Status    = opportunity.Status.Name,
                        Trader    = opportunity.Trader.FirstName + " " + opportunity.Trader.LastName
                    };

                    var counter = 1;
                    foreach (var position in opportunity.Positions)
                    {
                        oppoRes.Positions.Add(new SellOpportunityPositionDetailsDto
                        {
                            Deleted           = false,
                            GrossValue        = position.GrossValue,
                            Id                = position.Id,
                            LocalId           = counter,
                            Markup            = position.Markup,
                            NetValue          = position.NetValue,
                            Product           = position.Product.Name,
                            Quantity          = position.Quantity,
                            VatValue          = position.VatValue,
                            UnitOfMeasurement = position.Product.UnitOfMeasurement
                        });
                        counter += 1;
                    }
                }
                else
                {
                    oppoRes = new SellOpportunityDetailsDto
                    {
                        Lead      = "",
                        Positions = new List <SellOpportunityPositionDetailsDto>(),
                        Status    = "",
                        Trader    = ""
                    };
                }

                var response = new SellOpportunityDetailsResponseDto
                {
                    CompanyTraders = tradersList.Select(x => (x.FirstName + " " + x.LastName)).ToList(),
                    Leads          = leads.Select(x => (x.Name + "," + x.NIP)).ToList(),
                    Products       = products.Select(x => new ProductForListDto
                    {
                        Id                = x.Id,
                        Name              = x.Name,
                        MarkupRate        = x.MarkupRate,
                        UnitOfMeasurement = x.UnitOfMeasurement,
                        UnitValue         = x.UnitValue,
                        VatRate           = x.VatRate
                    }).ToList(),
                    SellOpportunity = oppoRes
                };

                return(new JsonResult(new ApiResponse <SellOpportunityDetailsResponseDto>
                {
                    Data = response,
                    Code = 200,
                    ErrorMessage = ""
                }));
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Data = null,
                    Code = 500,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
Exemple #9
0
        public async Task <IActionResult> Handle(GetLeadQuery request, CancellationToken cancellationToken)
        {
            try
            {
                var traders = await _userRepository.GetCompanyTraders(request.CompanyId);

                var user            = traders.FirstOrDefault(x => x.Id == request.UserId);
                var responseTraders = new List <string>();

                foreach (var trader in traders)
                {
                    responseTraders.Add(trader.FirstName + " " + trader.LastName);
                }

                if (request.Id == 0)
                {
                    return(new JsonResult(new ApiResponse <LeadDetailsDto>
                    {
                        Code = 200,
                        ErrorMessage = "",
                        Data = new LeadDetailsDto
                        {
                            Lead = new LeadForDetailsDto
                            {
                                Id = 0,
                                Activities = new List <ActivityDetailsDto>(),
                                LeadAddress = new LeadAddressDto
                                {
                                    Id = 0,
                                    ApartmentNumber = "",
                                    City = "",
                                    HouseNumber = "",
                                    PostCode = "",
                                    Province = "",
                                    Street = ""
                                },
                                LeadContacts = new List <LeadContactDto>(),
                                LeadStatus = "",
                                Name = "",
                                NIP = "",
                                Regon = "",
                                User = ""
                            },
                            CompanyTraders = responseTraders,
                            User = user.FirstName + " " + user.LastName
                        }
                    }));
                }

                var lead = await _leadRepository.GetLeadAsync(request.Id, request.CompanyId);

                if (lead.UserId != request.UserId)
                {
                    if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, request.UserId, "Modyfikacja cudzych leadów")))
                    {
                        return(new JsonResult(new ApiResponse <object>
                        {
                            Data = null,
                            Code = 403,
                            ErrorMessage = "Brak uprawnień"
                        }));
                    }
                }

                if (lead != null)
                {
                    var leadResponse = new LeadForDetailsDto
                    {
                        Id           = lead.Id,
                        Activities   = new List <ActivityDetailsDto>(),
                        LeadContacts = new List <LeadContactDto>(),
                        LeadStatus   = lead.LeadStatus.Name,
                        Name         = lead.Name,
                        NIP          = lead.NIP,
                        Regon        = lead.Regon,
                        User         = lead.User.FirstName + " " + lead.User.LastName
                    };

                    leadResponse.LeadAddress = new LeadAddressDto
                    {
                        Id = lead.LeadAddress.Id,
                        ApartmentNumber = lead.LeadAddress.ApartmentNumber,
                        City            = lead.LeadAddress.City,
                        HouseNumber     = lead.LeadAddress.HouseNumber,
                        PostCode        = lead.LeadAddress.PostCode,
                        Province        = lead.LeadAddress.Province,
                        Street          = lead.LeadAddress.Street
                    };

                    var counter = 1;
                    foreach (var contact in lead.LeadContacts)
                    {
                        leadResponse.LeadContacts.Add(new LeadContactDto
                        {
                            Deleted     = false,
                            Department  = contact.Department,
                            Email       = contact.Email,
                            Id          = contact.Id,
                            LocalId     = counter,
                            Name        = contact.Name,
                            PhoneNumber = contact.PhoneNumber
                        });
                        counter++;
                    }

                    counter = 1;
                    foreach (var activity in lead.Activities)
                    {
                        leadResponse.Activities.Add(new ActivityDetailsDto
                        {
                            Deleted      = false,
                            ActivityDate = activity.ActivityDate,
                            ActivityType = activity.ActivityType.Name,
                            LocalId      = counter,
                            Id           = activity.Id,
                            User         = activity.User.FirstName + " " + activity.User.LastName
                        });
                        counter++;
                    }

                    return(new JsonResult(new ApiResponse <LeadDetailsDto>
                    {
                        Code = 200,
                        ErrorMessage = "",
                        Data = new LeadDetailsDto
                        {
                            Lead = leadResponse,
                            CompanyTraders = responseTraders,
                            User = user.FirstName + " " + user.LastName
                        }
                    }));
                }

                return(new JsonResult(new ApiResponse <object>
                {
                    Data = null,
                    Code = 404,
                    ErrorMessage = "Nie znaleziono leada o id=" + request.Id + ", skontaktuj się z działem IT."
                }));
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Data = null,
                    Code = 500,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
Exemple #10
0
        public async Task <IActionResult> Handle(GetUserDataQuery request, CancellationToken cancellationToken)
        {
            try
            {
                if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, request.RequestUserId, "Panel administracji")))
                {
                    return(new JsonResult(new ApiResponse <object>
                    {
                        Data = null,
                        Code = 403,
                        ErrorMessage = "Brak uprawnień"
                    }));
                }

                var user = await _userRepository.GetUserByIdAsync(request.UserId);

                if (user != null)
                {
                    var userData = new UserUpsertDto
                    {
                        Id      = user.Id,
                        Address = new AddressDto
                        {
                            Id = user.Address.Id,
                            ApartmentNumber = user.Address.ApartmentNumber,
                            City            = user.Address.City,
                            HouseNumber     = user.Address.HouseNumber,
                            PostCode        = user.Address.PostCode,
                            Province        = user.Address.Province,
                            Street          = user.Address.Street
                        },
                        Department  = user.CompanyPosition,
                        Email       = user.Email,
                        FirstName   = user.FirstName,
                        Gender      = user.Gender,
                        LastName    = user.LastName,
                        Login       = user.UserName,
                        Password    = "",
                        Permissions = new List <PermissionDto>(),
                        PhoneNumber = user.PhoneNumber
                    };

                    var allPerm = await _userRepository.GetAppClaims();

                    var userPerms = await _userRepository.GetUserClaims(user.Id);

                    foreach (var claim in allPerm)
                    {
                        userData.Permissions.Add(new PermissionDto
                        {
                            Name     = claim,
                            Selected = userPerms.Contains(claim)
                        });
                    }

                    return(new JsonResult(new ApiResponse <UserUpsertDto>
                    {
                        Code = 200,
                        Data = userData,
                        ErrorMessage = ""
                    }));
                }
                else
                {
                    var userData = new UserUpsertDto
                    {
                        Id      = "",
                        Address = new AddressDto
                        {
                            Id = 0,
                            ApartmentNumber = "",
                            City            = "",
                            HouseNumber     = "",
                            PostCode        = "",
                            Province        = "",
                            Street          = ""
                        },
                        Department  = "",
                        Email       = "",
                        FirstName   = "",
                        Gender      = false,
                        LastName    = "",
                        Login       = "",
                        Password    = "",
                        Permissions = new List <PermissionDto>(),
                        PhoneNumber = ""
                    };

                    var allPerm = await _userRepository.GetAppClaims();

                    foreach (var claim in allPerm)
                    {
                        userData.Permissions.Add(new PermissionDto
                        {
                            Name     = claim,
                            Selected = false
                        });
                    }

                    return(new JsonResult(new ApiResponse <UserUpsertDto>
                    {
                        Code = 200,
                        Data = userData,
                        ErrorMessage = ""
                    }));
                }
            }
            catch
            {
                return(new JsonResult(new ApiResponse <object>
                {
                    Code = 500,
                    Data = null,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                }));
            }
        }
Exemple #11
0
        public async Task<IActionResult> Handle(UpdateCompanyCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var validator = new UpdateCompanyValidator();
                var result = validator.Validate(request.Dto);
                if (!result.IsValid)
                {
                    var errorMsg = "";

                    foreach (var err in result.Errors)
                    {
                        errorMsg += err.ErrorMessage + "\r\n";
                    }

                    return new JsonResult(new ApiResponse<object>
                    {
                        Code = 406,
                        ErrorMessage = errorMsg,
                        Data = null
                    });
                }

                if (!(await PermissionMonitor.CheckPermissionsAsync(_userRepository, request.UserId, "Panel administracji")))
                {
                    return new JsonResult(new ApiResponse<object>
                    {
                        Data = null,
                        Code = 403,
                        ErrorMessage = "Brak uprawnień"
                    });
                }

                var company = new Company
                {
                    Address = new Address
                    {
                        ApartmentNumber = request.Dto.Address.ApartmentNumber,
                        City = request.Dto.Address.City,
                        HouseNumber = request.Dto.Address.HouseNumber,
                        Id = request.Dto.Address.Id,
                        PostCode = request.Dto.Address.PostCode,
                        Province = request.Dto.Address.Province,
                        Street = request.Dto.Address.Street
                    },
                    Id = request.Dto.Id,
                    CompanyName = request.Dto.Name,
                    NIP = request.Dto.Nip,
                    Regon = request.Dto.Regon
                };

                await _companyRepository.UpdateCompanyAsync(company);

                return new JsonResult(new ApiResponse<object>
                {
                    Code = 201,
                    Data = null,
                    ErrorMessage = ""
                });
            }
            catch
            {
                return new JsonResult(new ApiResponse<object>
                {
                    Code = 500,
                    Data = null,
                    ErrorMessage = "Nastąpił problem z serwerem, skontaktuj się z działem IT."
                });
            }
        }