public ServisModel AddServis(ServisInsertRequest request) { var entity = _mapper.Map <Database.Servisi>(request); Recommender recommender = new Recommender(_context, _mapper); var dodjeljeniServiser = recommender.GetServisera(request.UredjajId); if (dodjeljeniServiser == null) { dodjeljeniServiser = _context.KorisniciUloge.Include(k => k.Korisnik).Where(ko => ko.Uloga.Naziv == "serviser").Select(k => k.Korisnik).FirstOrDefault(); } entity.ServiserId = dodjeljeniServiser.KorisnikId; var status1 = _context.StatusServisa.Where(x => x.Naziv == "Servis napravljen").FirstOrDefault(); var status2 = _context.StatusServisa.Where(x => x.Naziv == "Servis dodjeljen serviseru").FirstOrDefault(); entity.StatusServisaId = status2.StatusServisaId; _context.Servisi.Add(entity); _context.SaveChanges(); StanjeServisa ss1 = new StanjeServisa(); ss1.Azurirano = DateTime.Now; ss1.Napomena = "Servir kreiran"; ss1.ServisId = entity.ServisId; ss1.StatusServisaId = status1.StatusServisaId; _context.StanjeServisa.Add(ss1); _context.SaveChanges(); StanjeServisa ss2 = new StanjeServisa(); ss2.Azurirano = DateTime.Now; ss2.Napomena = "Servis uspjesno dodjeljen serviseru"; ss2.ServisId = entity.ServisId; ss2.StatusServisaId = status2.StatusServisaId; _context.StanjeServisa.Add(ss2); _context.SaveChanges(); return(_mapper.Map <ServisModel>(entity)); }