Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public StanjeServisaInsertRequest StanjeServisaAdd(StanjeServisaInsertRequest request)
        {
            var entity = new StanjeServisa();

            entity.Azurirano = request.Azurirano;
            entity.Napomena  = request.Napomena;
            entity.ServisId  = request.ServisId;
            var statusServisa = _context.StatusServisa.Where(x => x.Naziv == request.TrenutniStatus).FirstOrDefault();

            entity.StatusServisaId = statusServisa.StatusServisaId;
            _context.StanjeServisa.Add(entity);
            _context.SaveChanges();
            var servis = _context.Servisi.Find(request.ServisId);

            if (request.Ocijena != 0)
            {
                servis.OcjenaServisa = request.Ocijena;
            }
            if (request.Cijena != 0)
            {
                servis.Cijena = request.Cijena;
            }
            servis.StatusServisaId = statusServisa.StatusServisaId;
            _context.Servisi.Update(servis);
            _context.SaveChanges();
            var zavrsniStatusServisa = _context.StatusServisa.Where(x => x.Naziv == "Servis zavrsen").FirstOrDefault();

            //Send Email Does not work locally with emulators (Needs SSL for Sending Mail, but emulator does not work with SSL)
            //if (entity.StatusServisaId == zavrsniStatusServisa.StatusServisaId)
            //{
            //    var klijent = _context.Korisnici.Where(x => x.KorisnikId == servis.KlijentId).FirstOrDefault();
            //    using (MailMessage mm = new MailMessage("", klijent.Email))
            //    {
            //        mm.Subject = "Servis završen";
            //        mm.Body = "Vaš uređaj je spreman, provjerite na aplikaciji stanje.";
            //        mm.IsBodyHtml = false;
            //        using (SmtpClient smtp = new SmtpClient())
            //        {
            //            smtp.Host = "smtp.gmail.com";
            //            smtp.EnableSsl = true;
            //            NetworkCredential NetworkCred = new NetworkCredential("", "");
            //            smtp.UseDefaultCredentials = true;
            //            smtp.Credentials = NetworkCred;
            //            smtp.Port = 587;
            //            smtp.Send(mm);
            //        }
            //    }
            //}
            return(request);
        }