Esempio n. 1
0
        public async Task <List <OutProizvodDTO> > GetAllForUser(HttpContext context)
        {
            string userId = TokensHelper.GetClaimFromJwt(context, CustomClaims.UserId.ToString());

            var proizvodi = await _db.Proizvodi.Include(i => i.Prodavac).Where(p => p.Prodavac.Id == userId).ToListAsync();

            List <OutProizvodDTO> outProizvodi = new List <OutProizvodDTO>();

            foreach (var proizvod in proizvodi)
            {
                string slika = null;

                try
                {
                    using var buffer = await GetImage(proizvod.Id);

                    slika = Convert.ToBase64String(buffer.GetBuffer());
                }
                catch (Exception) { }

                outProizvodi.Add(new OutProizvodDTO
                {
                    Id              = proizvod.Id,
                    Naziv           = proizvod.Naziv,
                    Cena            = proizvod.Cena,
                    Opis            = null,
                    NacinKoriscenja = proizvod.NacinKoriscenja,
                    Prodavac        = null,
                    Slika           = slika
                });
            }

            return(outProizvodi);
        }
Esempio n. 2
0
        public async Task <Account> Update(HttpContext context, Update model)
        {
            string userName = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);

            var user = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                throw new ErrorException(ErrorCode.UserNotFound, "Korisnik ne postoji u sistemu.");
            }

            user.FirstName   = model.FirstName;
            user.LastName    = model.LastName;
            user.PhoneNumber = model.PhoneNumber;
            user.Address     = model.Address;

            var res = await _userManager.UpdateAsync(user);

            if (!res.Succeeded)
            {
                throw new ErrorException(ErrorCode.UserUpdateError, "Greška pri čuvanju profila.");
            }

            return(new Account
            {
                Username = user.UserName,
                Email = user.Email,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Address = user.Address,
                PhoneNumber = user.PhoneNumber
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Async method to call into RPaaS through ARM to get metadata from the storage layer.
        /// </summary>
        /// <param name="requestUri">The request URI.</param>
        /// <param name="tenantId">The tenant Id.</param>
        /// <param name="httpMethod">The HTTP method.</param>
        /// <param name="resource">The resource.</param>
        private async Task <HttpResponseMessage> CallRPSaaSForMetadata(Uri requestUri, string tenantId, HttpMethod httpMethod, Resource resource = null)
        {
            using (var httpClient = new HttpClient())
            {
                var authenticationResult = await TokensHelper.GetAccessToken(this.Configuration, tenantId).ConfigureAwait(false);

                var proxyRequest = new HttpRequestMessage(httpMethod, requestUri);

                if (authenticationResult?.AccessToken != null)
                {
                    Logger.LogMessage("Got access token successfully");
                    proxyRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken);
                }

                if (resource != null)
                {
                    var json = JsonConvert.SerializeObject(resource, ObjectSerializationSettings);
                    proxyRequest.Content = new StringContent(json, Encoding.UTF8, "application/json");
                }

                Logger.LogMessage($"Calling ARM to '{httpMethod}' for '{requestUri}'");

                return(await httpClient.SendAsync(proxyRequest).ConfigureAwait(false));
            }
        }
Esempio n. 4
0
        public async Task <byte[]> GetImage(HttpContext context)
        {
            try
            {
                var path1 = Path.Combine("Resources", "Images");
                var path  = Path.Combine(path1, "Avatars");

                string userName  = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);
                string imageName = userName;

                //var fileName = Directory.EnumerateFiles(@path, imageName).FirstOrDefault();

                var fileName = Path.Combine(path, imageName);

                using var memory = new MemoryStream();
                using (var stream = new FileStream(fileName, FileMode.Open))
                {
                    await stream.CopyToAsync(memory);
                }
                memory.Position = 0;

                return(memory.GetBuffer());
            }
            catch (Exception)
            {
                throw new ErrorException(ErrorCode.ImageNotFound, "Slika nije pronađena.");
            }
        }
Esempio n. 5
0
        public async Task <bool> Delete(HttpContext context)
        {
            string userName = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);

            var user = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                return(true);
            }

            var res = await _userManager.DeleteAsync(user);

            try
            {
                DeleteImage(context);
            }
            catch (Exception) { }

            if (!res.Succeeded)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        public ApplicationToken CreateNewToken(int id, int tokenId, LoggedInUserDetails user)
        {
            // Check whehter organisation is not active
            if (!user.Organization.IsActive)
            {
                throw new BaseException(
                          "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator.");
            }

            // Check whether application belongs to a user
            _security.CheckAccessToApplication(user, id);

            // Get application token
            var appToken = _tokens.FirstOrDefault(i => i.ID == tokenId);

            // Check whether app token not found
            if (appToken == null)
            {
                throw new BaseException("Unable to find service host.");
            }

            // Generate new token
            var generatedToken = TokensHelper.GenerateToken();
            var result         = new ApplicationToken()
            {
                ApplicationID = appToken.ApplicationID,
                OriginHost    = appToken.OriginHost,
                Token         = generatedToken,
                CreatedAt     = GetDate,
                CreatedBy     = user.ID.Value
            };

            // Save token
            _tokens.Add(result);

            // Setup expiration details for old token
            appToken.ExpiredAt = GetDate;
            appToken.ExpiredBy = user.ID.Value;

            // Save changes
            _tokens.Update(appToken);

            // Return result
            return(result);
        }
Esempio n. 7
0
        public async Task <OutProizvodDTO> Add(InProductDTO model, HttpContext context)
        {
            string userName = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);

            var user = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                throw new ErrorException(ErrorCode.UserNotFound, "Prodavac ne postoji u sistemu.");
            }

            Guid id = Guid.NewGuid();

            _db.Proizvodi.Add(new Proizvod
            {
                Id              = id,
                Naziv           = model.Naziv,
                Cena            = model.Cena,
                Opis            = model.Opis,
                NacinKoriscenja = model.NacinKoriscenja,
                Prodavac        = user
            });

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw new ErrorException(ErrorCode.DbError, "Greška pri čuvanju proizvoda u bazu podataka.");
            }

            return(new OutProizvodDTO
            {
                Id = id,
                Naziv = model.Naziv,
                Cena = model.Cena,
                Opis = model.Opis,
                NacinKoriscenja = model.NacinKoriscenja,
                Prodavac = null
            });
        }
Esempio n. 8
0
        public bool DeleteImage(HttpContext context)
        {
            try
            {
                var path1 = Path.Combine("Resources", "Images");
                var path  = Path.Combine(path1, "Avatars");

                string userName  = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);
                string imageName = userName;

                var fullPath = Path.Combine(path, imageName);

                File.Delete(fullPath);

                return(true);
            }
            catch (Exception)
            {
                throw new ErrorException(ErrorCode.ImageNotFound, "Greška pri brisanju slike.");
            }
        }
Esempio n. 9
0
        public async Task <UserAuthData> ChangePassword(HttpContext context, ChangePassword change)
        {
            string userName = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);

            var user = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                throw new ErrorException(ErrorCode.UserNotFound, "Korisnik ne postoji u sistemu.");
            }

            var res = await _userManager.ChangePasswordAsync(user, change.OldPassword, change.NewPassword);

            if (!res.Succeeded)
            {
                throw new ErrorException(ErrorCode.PasswordChangeFailed, "Greška pri menjanju lozinke.");
            }

            var role = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Role);

            return(await CreateTokens(user, role, true));
        }
Esempio n. 10
0
        public async Task <bool> SaveImage(HttpContext context)
        {
            IFormFile file;

            try
            {
                file = context.Request.Form.Files.FirstOrDefault(f => f.Name == "file");
                if (file == null)
                {
                    throw new ErrorException(ErrorCode.ImageNotFound, "Slika nije pronađena.");
                }
            }
            catch (Exception)
            {
                throw new ErrorException(ErrorCode.ImageNotFound, "Slika nije pronađena.");
            }
            if (file.Length > 10000000)
            {
                throw new ErrorException(ErrorCode.ImageTooLarge, "Slika zauzima previše prostora.");
            }

            string ext   = Path.GetExtension(file.FileName);
            var    path1 = Path.Combine("Resources", "Images");
            var    path  = Path.Combine(path1, "Avatars");

            string userName  = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);
            string imageName = userName;

            var fullPath = Path.Combine(path, imageName);

            using (var stream = new FileStream(fullPath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }

            return(true);
        }
Esempio n. 11
0
        public void AddHost(int id, string host, LoggedInUserDetails user)
        {
            // Check whether organisation is not active
            if (!user.Organization.IsActive)
            {
                throw new BaseException(
                          "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator.");
            }

            // Check whether host is a valid uri
            var isValidUrl = Uri.TryCreate(host, UriKind.Absolute, out var result);

            // Check whether url scheme specified
            var urlWithScheme = isValidUrl && (result.Scheme == Uri.UriSchemeHttp || result.Scheme == Uri.UriSchemeHttps);

            if (!urlWithScheme)
            {
                throw new BaseException($"Invalid host '{result}'");
            }

            // Get application
            var application = _security.CheckAccessToApplication(user, id);

            // Setup new application token
            var appToken = new ApplicationToken
            {
                ApplicationID = application.ID,
                OriginHost    = host,
                Token         = TokensHelper.GenerateToken(),
                CreatedAt     = GetDate,
                CreatedBy     = user.ID.Value
            };

            // Add new token
            _tokens.Add(appToken);
        }
Esempio n. 12
0
        public async Task <Account> Get(HttpContext context)
        {
            string userName = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);

            var user = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                throw new ErrorException(ErrorCode.UserNotFound, "Korisnik ne postoji u sistemu.");
            }

            var role = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Role);

            return(new Account
            {
                Username = user.UserName,
                Email = user.Email,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Address = user.Address,
                PhoneNumber = user.PhoneNumber,
                Role = role
            });
        }
Esempio n. 13
0
        public Application Create(string url, NewApplicationDetails model, LoggedInUserDetails user)
        {
            // Check whether user has access
            if (user.IsSysAdmin)
            {
                throw new BaseException("Admin can not create an application.");
            }

            // Check whether organisation is active
            if (!user.Organization.IsActive)
            {
                throw new BaseException(
                          "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator.");
            }

            // Check whether application name already used within the organisation
            if (IsApplicationExistsForThisOrganization(model.Name, string.Empty, user))
            {
                throw new BaseException("Application name already in use.");
            }

            // Check whether hosts provided
            if (string.IsNullOrEmpty(model.OriginHosts))
            {
                throw new BaseException("You should define at least one host.");
            }

            // TODO: check whether all required data provided[Failed when auth tab was now shown in create provider app]

            // Setup application model
            var application = new Application
            {
                Name        = model.Name,
                Description = model.Description,
                PublicID    = Guid.NewGuid(),
                IsProvider  = model.IsProvider,
                IsIntroducedAsIndustryGood = model.IsIntroducedAsIndustryGood,
                OrganizationID             = user.Organization.ID,
                CreatedAt = GetDate,
                IsActive  = !model.IsIntroducedAsIndustryGood,
                CreatedBy = user.ID.Value
            };

            // Add application
            _applications.Add(application);

            if (application.IsProvider)
            {
                // Setup application authentication
                var appAuth = new ApplicationAuthentication
                {
                    ApplicationID         = application.ID,
                    WellKnownUrl          = string.IsNullOrEmpty(model.WellKnownUrl) ? string.Empty : model.WellKnownUrl,
                    Issuer                = string.IsNullOrEmpty(model.Issuer) ? string.Empty : model.Issuer,
                    JwksUri               = string.IsNullOrEmpty(model.JwksUri) ? string.Empty : model.JwksUri,
                    AuthorizationEndpoint = model.AuthorizationEndpoint,
                    TokenEndpoint         = model.TokenEndpoint,
                    RegistrationEndpoint  = model.RegistrationEndpoint,
                    UserInfoEndpoint      = string.Empty,
                    EndSessionEndpoint    = string.Empty,
                    CheckSessionIFrame    = string.Empty,
                    RevocationEndpoint    = string.Empty,
                    CreatedAt             = GetDate,
                    CreatedBy             = user.ID.Value
                };

                // Add application authentication
                _authentications.Add(appAuth);
            }

            foreach (var host in model.OriginHosts.Split(','))
            {
                var appToken = new ApplicationToken()
                {
                    ApplicationID = application.ID,
                    OriginHost    = host,
                    Token         = TokensHelper.GenerateToken(),
                    CreatedAt     = GetDate,
                    CreatedBy     = user.ID.Value
                };

                // Add token
                _tokens.Add(appToken);
            }

            // Send verification request to admin for industry good application
            if (application.IsIntroducedAsIndustryGood)
            {
                _notifications.Admin.NewIndustryGoodApplicationInBackground(url, application.OrganizationID);
            }

            return(application);
        }
Esempio n. 14
0
 public Tokenizer(IMemoryCache memoryCache, TokensHelper tokenHelper)
 {
     _memoryCache = memoryCache;
     _tokenHelper = tokenHelper;
 }
Esempio n. 15
0
        public async Task <List <OutOrderDTO> > Add(InOrderDTO model, HttpContext context)
        {
            if (model == null || model.ListaElemenata == null || model.ListaElemenata.Count == 0)
            {
                return(null);
            }

            string userName = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);

            var user = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                throw new ErrorException(ErrorCode.UserNotFound, "Prodavac ne postoji u sistemu.");
            }

            var listaNarudzbina = new List <Narudzbina>();

            foreach (var el in model.ListaElemenata)
            {
                var proizvod = _db.Proizvodi.Where(p => p.Id == el.Id)?.Include(i => i.Prodavac).FirstOrDefault();
                if (proizvod == null)
                {
                    continue;
                }
                var narudzbinaZaOvogProdavca = listaNarudzbina.FirstOrDefault(n => n.Prodavac.Id == proizvod.Prodavac.Id);
                if (narudzbinaZaOvogProdavca == null)
                {
                    narudzbinaZaOvogProdavca = new Narudzbina
                    {
                        Id             = Guid.NewGuid(),
                        ListaElemenata = new List <ElementKorpe>
                        {
                            new ElementKorpe
                            {
                                Id       = Guid.NewGuid(),
                                Kolicina = el.Kolicina,
                                Proizvod = proizvod
                            }
                        },
                        Kupac                = user,
                        StatusNarudzbine     = StatusNarudzbine.Nova,
                        VremeIsporukeUDanima = null,
                        Prodavac             = proizvod.Prodavac
                    };
                    listaNarudzbina.Add(narudzbinaZaOvogProdavca);
                }
                else
                {
                    narudzbinaZaOvogProdavca.ListaElemenata.Add(new ElementKorpe
                    {
                        Id       = Guid.NewGuid(),
                        Kolicina = el.Kolicina,
                        Proizvod = proizvod
                    });
                }
            }

            foreach (var narudzbina in listaNarudzbina)
            {
                narudzbina.DatumNarudzbine = DateTime.UtcNow;
                _db.Narudzbine.Add(narudzbina);
            }

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw new ErrorException(ErrorCode.DbError, "Greška pri čuvanju narudzbine u bazu podataka.");
            }

            var outListaNarudzbina = new List <OutOrderDTO>();

            foreach (var narudzbina in listaNarudzbina)
            {
                var outNar = new OutOrderDTO
                {
                    Id       = narudzbina.Id,
                    Prodavac = new Account
                    {
                        FirstName   = narudzbina.Prodavac.FirstName,
                        LastName    = narudzbina.Prodavac.LastName,
                        Email       = narudzbina.Prodavac.Email,
                        PhoneNumber = narudzbina.Prodavac.PhoneNumber
                    },
                    ListaElemenata = new List <OutElementKorpeDTO>()
                };
                foreach (var el in narudzbina.ListaElemenata)
                {
                    outNar.ListaElemenata.Add(new OutElementKorpeDTO
                    {
                        Kolicina = el.Kolicina,
                        Proizvod = new OutProizvodDTO
                        {
                            Id              = el.Proizvod.Id,
                            Naziv           = el.Proizvod.Naziv,
                            Cena            = el.Proizvod.Cena,
                            Opis            = el.Proizvod.Opis,
                            NacinKoriscenja = el.Proizvod.NacinKoriscenja,
                            Prodavac        = null
                        }
                    });
                }
                outListaNarudzbina.Add(outNar);
            }

            return(outListaNarudzbina);
        }
Esempio n. 16
0
        public async Task <List <OutProdavacNarudzbinaDTO> > GetAllForBuyer(HttpContext context)
        {
            string userName = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);

            var user = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                throw new ErrorException(ErrorCode.UserNotFound, "Prodavac ne postoji u sistemu.");
            }

            var narudzbine = await _db.Narudzbine.Include(n => n.Kupac).Include(n => n.Prodavac)
                             .Include(n => n.ListaElemenata).ThenInclude(k => k.Proizvod).Where(k => k.Kupac == user)?.ToListAsync();

            if (narudzbine == null)
            {
                return(null);
            }

            List <OutProdavacNarudzbinaDTO> outProdavacNarudzbine = new List <OutProdavacNarudzbinaDTO>();

            foreach (var narudzbina in narudzbine)
            {
                var outProdavacNarudzbina = new OutProdavacNarudzbinaDTO
                {
                    Id = narudzbina.Id,
                    StatusNarudzbine     = narudzbina.StatusNarudzbine,
                    VremeIsporukeUDanima = narudzbina.VremeIsporukeUDanima,
                    Kupac = new Account
                    {
                        Address     = narudzbina.Kupac.Address,
                        Email       = narudzbina.Kupac.Email,
                        FirstName   = narudzbina.Kupac.FirstName,
                        LastName    = narudzbina.Kupac.LastName,
                        PhoneNumber = narudzbina.Kupac.PhoneNumber
                    },
                    Prodavac = new Account
                    {
                        Address     = narudzbina.Prodavac.Address,
                        Email       = narudzbina.Prodavac.Email,
                        FirstName   = narudzbina.Prodavac.FirstName,
                        LastName    = narudzbina.Prodavac.LastName,
                        PhoneNumber = narudzbina.Prodavac.PhoneNumber
                    },
                    ListaElemenata           = new List <OutElementKorpeDTO>(),
                    DatumNarudzbine          = narudzbina.DatumNarudzbine,
                    DatumOdobrenjaNarudzbine = narudzbina.DatumPotvrdeNarudzbine
                };
                foreach (var el in narudzbina.ListaElemenata)
                {
                    outProdavacNarudzbina.ListaElemenata.Add(new OutElementKorpeDTO
                    {
                        Kolicina = el.Kolicina,
                        Proizvod = new OutProizvodDTO
                        {
                            Id              = el.Proizvod.Id,
                            Naziv           = el.Proizvod.Naziv,
                            Cena            = el.Proizvod.Cena,
                            Opis            = el.Proizvod.Opis,
                            NacinKoriscenja = el.Proizvod.NacinKoriscenja,
                            Prodavac        = null
                        }
                    });
                }
                outProdavacNarudzbine.Add(outProdavacNarudzbina);
            }

            return(outProdavacNarudzbine);
        }
Esempio n. 17
0
        public async Task SignUpAsync_ValidTeam_SignsUp()
        {
            //Arrange
            var sut = CreateSut();

            var newTeam = new Team()
            {
                CreatedAt    = DateTime.Now,
                Name         = "Sign Up Test Team",
                Participants = new List <Participant>
                {
                    new Participant
                    {
                        Forename  = "John",
                        Surname   = "Doe",
                        Email     = "*****@*****.**",
                        CreatedAt = DateTime.Now,
                        Token     = new Token
                        {
                            Value     = "342345hjk34hgtkj34h5kjh345",
                            CreatedAt = DateTime.Now,
                            IsValid   = true,
                        }
                    },
                    new Participant
                    {
                        Forename  = "Mary",
                        Surname   = "Doe",
                        Email     = "*****@*****.**",
                        CreatedAt = DateTime.Now,
                        Token     = new Token
                        {
                            Value     = "lfkasdlfhjlkasdhf87",
                            CreatedAt = DateTime.Now,
                            IsValid   = true,
                        }
                    }
                }
            };

            //Act
            await sut.SignUpAsync(newTeam);

            //Assert
            var teams = await TeamsHelper.GetTeamsAsync();

            var team = teams.FirstOrDefault(t => t.Name == newTeam.Name);

            Assert.IsNotNull(team);

            Assert.AreEqual(newTeam.Name, team.Name);
            Assert.AreEqual(newTeam.CreatedAt.ToString(), team.CreatedAt.ToString());

            var participants = await ParticipantsHelper.GetParticipantsInTeamAsync(team.Id);

            var participant = newTeam.Participants[0];

            var john = participants.First(p => p.Forename == participant.Forename);

            Assert.IsNotNull(john);
            Assert.AreEqual(participant.Surname, john.Surname);
            Assert.AreEqual(participant.Email, john.Email);
            Assert.AreEqual(participant.CreatedAt.ToString(), john.CreatedAt.ToString());
            Assert.AreEqual(participant.TeamId, team.Id);

            var johnsToken = await TokensHelper.GetTokenForParticipantAsync(john.Id);

            Assert.AreEqual(participant.Token.Value, johnsToken.Value);
            Assert.AreEqual(participant.Token.CreatedAt.ToString(), participant.Token.CreatedAt.ToString());
            Assert.AreEqual(participant.Token.IsValid, participant.Token.IsValid);
            Assert.AreEqual(participant.Token.TeamId, team.Id);

            participant = newTeam.Participants[1];

            var mary = participants.First(p => p.Forename == participant.Forename);

            Assert.IsNotNull(mary);
            Assert.AreEqual(participant.Surname, mary.Surname);
            Assert.AreEqual(participant.Email, mary.Email);
            Assert.AreEqual(participant.CreatedAt.ToString(), mary.CreatedAt.ToString());
            Assert.AreEqual(participant.TeamId, team.Id);

            var marysToken = await TokensHelper.GetTokenForParticipantAsync(mary.Id);

            Assert.AreEqual(participant.Token.Value, marysToken.Value);
            Assert.AreEqual(participant.Token.CreatedAt.ToString(), participant.Token.CreatedAt.ToString());
            Assert.AreEqual(participant.Token.IsValid, participant.Token.IsValid);
            Assert.AreEqual(participant.Token.TeamId, team.Id);
        }
Esempio n. 18
0
        public async Task <OutProdavacNarudzbinaDTO> Get(Guid id, HttpContext context)
        {
            var narudzbina = await _db.Narudzbine.Include(n => n.Kupac).Include(n => n.Prodavac)
                             .Include(n => n.ListaElemenata).ThenInclude(k => k.Proizvod).FirstOrDefaultAsync(a => a.Id == id);

            if (narudzbina == null)
            {
                return(null);
            }

            string userName = TokensHelper.GetClaimFromJwt(context, ClaimTypes.Name);

            var user = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                throw new ErrorException(ErrorCode.UserNotFound, "Prodavac ne postoji u sistemu.");
            }

            if (narudzbina.Prodavac.Id != user.Id && narudzbina.Kupac.Id != user.Id)
            {
                throw new ErrorException(ErrorCode.OrderAccessError, "Nemate pravo da pristupite ovoj narudzbini.");
            }

            var outProdavacNarudzbina = new OutProdavacNarudzbinaDTO
            {
                Id = narudzbina.Id,
                StatusNarudzbine     = narudzbina.StatusNarudzbine,
                VremeIsporukeUDanima = narudzbina.VremeIsporukeUDanima,
                Prodavac             = new Account
                {
                    Address     = narudzbina.Prodavac.Address,
                    Email       = narudzbina.Prodavac.Email,
                    FirstName   = narudzbina.Prodavac.FirstName,
                    LastName    = narudzbina.Prodavac.LastName,
                    PhoneNumber = narudzbina.Prodavac.PhoneNumber
                },
                Kupac = new Account
                {
                    Address     = narudzbina.Kupac.Address,
                    Email       = narudzbina.Kupac.Email,
                    FirstName   = narudzbina.Kupac.FirstName,
                    LastName    = narudzbina.Kupac.LastName,
                    PhoneNumber = narudzbina.Kupac.PhoneNumber
                },
                ListaElemenata           = new List <OutElementKorpeDTO>(),
                DatumNarudzbine          = narudzbina.DatumNarudzbine,
                DatumOdobrenjaNarudzbine = narudzbina.DatumPotvrdeNarudzbine
            };

            foreach (var el in narudzbina.ListaElemenata)
            {
                outProdavacNarudzbina.ListaElemenata.Add(new OutElementKorpeDTO
                {
                    Kolicina = el.Kolicina,
                    Proizvod = new OutProizvodDTO
                    {
                        Id              = el.Proizvod.Id,
                        Naziv           = el.Proizvod.Naziv,
                        Cena            = el.Proizvod.Cena,
                        Opis            = el.Proizvod.Opis,
                        NacinKoriscenja = el.Proizvod.NacinKoriscenja,
                        Prodavac        = null
                    }
                });
            }

            return(outProdavacNarudzbina);
        }