private void DonatieAddAction() { var donatie = new Donatie { GrupaDeSange = AppSettings.LoggedDonator.GrupaDeSange, IdDonator = AppSettings.LoggedDonator.Id, DataDonare = DateTime.Now, InstitutieAsociata = AppSettings.LoggedDonator.Utilizator.InstitutieAsociata, EtapaDonare = "De Analizat" }; AppService.Instance.DonatieService.Add(donatie); var anunt = new AnuntDonator(); anunt.IdDonator = AppSettings.LoggedDonator.Id; anunt.TipAnuntDonator = TipAnuntDonator.Info.ToString(); anunt.DataAnunt = DateTime.Now; anunt.Mesaj = "Donatia ta a fost inregistrata cu succes!"; //TODO modifica aici ca sa vezi diferenta mai mare de timp var date = DateTime.Now; //date = date.AddMinutes(1); date = date.AddSeconds(5); AppSettings.LoggedDonator.DataDonarePosibila = date; AppService.Instance.DonatorService.Update(AppSettings.LoggedDonator); DonatieAdded?.Invoke(this, donatie); MessageBox.Show("Donatia ta a fost inregistrata! Vino la cel mai apropiat centru pentru urmatoarea etapa!", "Succes", MessageBoxButton.OK); }
public void InitializeTests() { _donator = new Donator { DataDonarePosibila = DateTime.Now, GrupaDeSange = 7, Nume = "TestFunctionalPrelucrare", Prenume = "TestFunctionalPrelucrare", TipUtilizator = "Donator", InstitutieAsociata = 10, UserName = "******", Password = "******" }; _donatorService.Add(_donator); // create a mock donatie _donatiePrelucrabila = new Donatie { GrupaDeSange = 6, DataDonare = DateTime.Now, IdDonator = _donator.Id, EtapaDonare = "Analizata", InstitutieAsociata = _donator.InstitutieAsociata, MotivRefuz = "" }; _donatieService.Add(_donatiePrelucrabila); }
public IEnumerable <Donatie> findAll() { lock (this) { log.Info("getting all donations"); IDbConnection con = dbUtils.DBUtils.getConnection(); /* Npgsql.NpgsqlConnection con1 = (Npgsql.NpgsqlConnection)con; * Npgsql.NpgsqlConnection.ClearPool(con1);*/ List <Donatie> donatii = new List <Donatie>(); using (var comm = con.CreateCommand()) { comm.CommandText = "select * from donatii"; using (var dataR = comm.ExecuteReader()) { while (dataR.Read()) { Donatie d = new Donatie((float)dataR.GetDouble(3), dataR.GetInt32(2), dataR.GetInt32(1)); d.Id = dataR.GetInt32(0); donatii.Add(d); } } } log.InfoFormat("exiting with value {0}", donatii); return(donatii); } }
public void PrelucreazaDonatie(Donatie donatie) { var compTrombocite = new Componenta() { TipComponenta = "Trombocite", IdDonatie = donatie.Id, DataDepunere = DateTime.Now, Stare = "In Asteptare" }; var compGlobuleR = new Componenta() { TipComponenta = "Globule Rosii", IdDonatie = donatie.Id, DataDepunere = DateTime.Now, Stare = "In Asteptare" }; var compPlasma = new Componenta() { TipComponenta = "Plasma", IdDonatie = donatie.Id, DataDepunere = DateTime.Now, Stare = "In Asteptare" }; try { _repository.Add(compTrombocite); _repository.Add(compGlobuleR); _repository.Add(compPlasma); } catch (ApplicationException) { throw new ServiceException("Something went wrong"); } }
public IEnumerable <Donatie> findAll() { log.Info("Entering findAll - Donatie"); IDbConnection con = DBUtils.getConnection(); IList <Donatie> donatii = new List <Donatie>(); using (var comm = con.CreateCommand()) { comm.CommandText = "select id,idD,idC,suma from donatii"; using (var dataR = comm.ExecuteReader()) { while (dataR.Read()) { int id = dataR.GetInt32(0); int idD = dataR.GetInt32(1); int idC = dataR.GetInt32(2); Double suma = dataR.GetDouble(3); Donatie donatie = new Donatie(id, idD, idC, suma); donatii.Add(donatie); } } } log.Info("Exiting findAll - Donatii"); return(donatii); }
public void Update(Donatie donatie) { Donatie oldDonatie = _repository.Find(donatie.Id); if (!oldDonatie.EtapaDonare.Equals(donatie)) { // s-a schimbat etapa de donare, anuntam donatorul AnuntDonator anunt = new AnuntDonator(); anunt.IdDonator = donatie.IdDonator; anunt.Mesaj = "Etapa donarii tale s-a schimbat din " + oldDonatie.EtapaDonare + " in " + donatie.EtapaDonare + ". "; if (null == donatie.MotivRefuz) { anunt.TipAnuntDonator = "Informare"; } else { anunt.TipAnuntDonator = "Refuz"; anunt.Mesaj += "Motivul refuzului: " + donatie.MotivRefuz + "."; } anunt.DataAnunt = DateTime.Now; AppService.Instance.AnuntDonatorService.Add(anunt); } _repository.Update(donatie); }
public static DonatieDTO getDTO(Donatie donatie) { int id = donatie.Id; int idD = donatie.IdD; int idC = donatie.IdC; double sumaDonatie = donatie.Suma; return(new DonatieDTO(id, idD, idC, sumaDonatie)); }
public static Donatie[] getFromDTO(DonatieDTO[] donatii) { Donatie[] don = new Donatie[donatii.Length]; for (int i = 0; i < donatii.Length; i++) { don[i] = getFromDTO(donatii[i]); } return(don); }
public void valideaza(Donatie d) { Errors = ""; if (d.sumaDonata <= 0F) { Errors += "suma invalida!"; } if (Errors.Length > 0) { throw new Exception(Errors); } }
public void addDonatie(Donatie donatie) { DonatieDTO donatieDTO = DTOUtils.getDTO(donatie); sendRequest(new SaveDonatieRequest(donatieDTO)); Response response = readResponse(); if (response is ErrorResponse) { ErrorResponse err = (ErrorResponse)response; throw new MyException(err.Message); } }
public void Save() { if (String.IsNullOrEmpty(NumeDonator) || String.IsNullOrEmpty(PrenumeDonator) || DonatieViewModel.DataDonare == null || String.IsNullOrEmpty(Etapa) || SelectedInstitutie == null) { MessageBox.Show("Plase make sure you completed all the fields correctly..", "Error", MessageBoxButton.OK); } else { try { Donator Donator = AppService.Instance.DonatorService.getDonatorByName(NumeDonator, PrenumeDonator); DonatieViewModel.DonatorId = Donator.Id; DonatieViewModel.EtapaDonare = Etapa; DonatieViewModel.MotivRefuz = MotivRefuz; DonatieViewModel.GrupaDeSangeId = Donator.GrupaDeSange; DonatieViewModel.InstitutieAsociataId = SelectedInstitutie.Id; var donatie = new Donatie() { Id = DonatieViewModel.Id, IdDonator = DonatieViewModel.DonatorId, DataDonare = DonatieViewModel.DataDonare, EtapaDonare = DonatieViewModel.EtapaDonare, InstitutieAsociata = DonatieViewModel.InstitutieAsociataId, GrupaDeSange = DonatieViewModel.GrupaDeSangeId, MotivRefuz = MotivRefuz }; if (DonatieViewModel.Id == 0) { AppService.Instance.DonatieService.Add(donatie); MessageBox.Show("Donation added successfully!", "Success", MessageBoxButton.OK); DonatieAdded?.Invoke(this, donatie); } else { AppService.Instance.DonatieService.Update(donatie); MessageBox.Show("You have successfully updated the Donation!", "Success", MessageBoxButton.OK); DonatieUpdated?.Invoke(this, donatie); } } catch (ServiceException e) { MessageBox.Show(e.Message, "Error", MessageBoxButton.OK); } } }
public void donatieAdded(Donatie donatie) { DonatieDTO dto = DTOUtils.getDTO(donatie); Console.WriteLine("Donatie received " + donatie); try { sendResponse(new SaveDonatieResponse(dto)); } catch (Exception e) { throw new MyException("Sending error: " + e); } }
public void donatieS(float sumaDonata, int idDonator, int cazId) { Donatie d = new Donatie(sumaDonata, idDonator, cazId); try { validatorDonatii.valideaza(d); } catch (Exception e) { } donatiiDBRepository.save(d); notifyAllAngajatiDonatie(); }
public DonatieViewModel(Donatie donatie) { Donatie = donatie; DataDonare = donatie.DataDonare; EtapaDonare = donatie.EtapaDonare; GrupaDeSangeId = donatie.GrupaDeSange; GrupaDeSange = donatie.GrupaDeSangeObj; InstitutieAsociataId = donatie.InstitutieAsociata; InstitutieAsociataObj = donatie.InstitutieAsociataObj; MotivRefuz = donatie.MotivRefuz; Id = donatie.Id; DonatorId = donatie.IdDonator; Donator = donatie.Donator; }
// GET: Donatie/Delete/5 public ActionResult Delete(Guid id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Donatie donatie = db.Donatii.Find(id); if (donatie == null) { return(HttpNotFound()); } return(View(donatie)); }
public ActionResult DeleteConfirmed(Guid id) { try { Donatie donatie = db.Donatii.Find(id); db.Donatii.Remove(donatie); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public void save(Donatie entity) { log.InfoFormat("adding donation for {0}", entity.idCazCaritabil); IDbConnection con = dbUtils.DBUtils.getConnection(); using (var comm = con.CreateCommand()) { // verificam daca exista ce vrem sa updatam comm.CommandText = "select * from donatii where id_donatie = @id"; IDbDataParameter paramId = comm.CreateParameter(); paramId.ParameterName = "@id"; paramId.Value = entity.Id; comm.Parameters.Add(paramId); using (var dataR = comm.ExecuteReader()) { if (dataR.Read()) { return; } } comm.CommandText = "insert into donatii(id_caz, id_donator, suma) values (@caz, @don, @suma)"; var paramName = comm.CreateParameter(); paramName.ParameterName = "@caz"; paramName.Value = entity.idCazCaritabil; comm.Parameters.Add(paramName); var paramTel = comm.CreateParameter(); paramTel.ParameterName = "@don"; paramTel.Value = entity.idDonator; comm.Parameters.Add(paramTel); var paramAddr = comm.CreateParameter(); paramAddr.ParameterName = "@suma"; paramAddr.Value = entity.sumaDonata; comm.Parameters.Add(paramAddr); var result = comm.ExecuteNonQuery(); if (result == 0) { log.Error("No donation added!"); throw new RepositoryException("No donation added!"); } } log.Info("exit save"); }
public ActionResult Create([Bind(Include = "Id,IdUtilizator,Data,Centru,Oras,TipDonatie")] Donatie donatie) { try { donatie.Id = Guid.NewGuid(); donatie.IdUtilizator = User.Identity.GetUserId(); db.Donatii.Add(donatie); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View(donatie)); } }
private void handleUpdate(UpdateResponse update) { if (update is UpdateCazResponse) { UpdateCazResponse frUpd = (UpdateCazResponse)update; CazCaritabil caz = DTOUtils.getFromDTO(frUpd.Caz); Console.WriteLine("Updated caz " + caz); try { client.updateSC(caz); } catch (MyException e) { Console.WriteLine(e.StackTrace); } } if (update is SaveDonatorResponse) { SaveDonatorResponse donRes = (SaveDonatorResponse)update; Donator donator = DTOUtils.getFromDTO(donRes.Donator); try { client.updateDonator(donator); } catch (MyException e) { Console.WriteLine(e.StackTrace); } } if (update is SaveDonatieResponse) { SaveDonatieResponse donRes = (SaveDonatieResponse)update; Donatie donatie = DTOUtils.getFromDTO(donRes.Add); try { client.donatieAdded(donatie); } catch (MyException e) { Console.WriteLine(e.StackTrace); } } }
// GET: Programare public ActionResult Index() { var currentUserId = User.Identity.GetUserId(); var profil = db.Profiluri.First(x => x.IdUtilizator == currentUserId); var currentUser = db.Users.FirstOrDefault(u => u.Id == currentUserId); var donatii = db.Donatii.Where(x => x.IdUtilizator == currentUserId).OrderByDescending(x => x.Data); var ultimaDonatie = new Donatie(); if (donatii.Any()) { ultimaDonatie = db.Donatii.Where(x => x.IdUtilizator == currentUserId).OrderByDescending(x => x.Data).First(); } else { ultimaDonatie = null; } DateTime dataUrmatoareiDonatii; TipDonatie tipDonatie; int interval = 16; if (ultimaDonatie == null) { dataUrmatoareiDonatii = DateTime.Today; } else { tipDonatie = ultimaDonatie.TipDonatie; var existaInterval = db.PerioadeAsteptare.First(x => x.IdUtilizator == currentUserId && x.TipDonatie == tipDonatie); interval = existaInterval != null ? existaInterval.Interval : 16; dataUrmatoareiDonatii = ultimaDonatie.Data.AddDays(interval * 7); } var zileRamase = DateTime.Today.Date < dataUrmatoareiDonatii.Date ? (dataUrmatoareiDonatii.Date - DateTime.Today.Date).Days : 0; ViewBag.total = interval * 7; ViewBag.left = zileRamase; var progres = interval * 7 - zileRamase; ViewBag.progres = (progres * 100) / (interval * 7); ViewBag.data = dataUrmatoareiDonatii; ViewBag.sex = profil.Sex; ViewBag.oras = profil.Oras; return(View()); }
private void button1_Click(object sender, EventArgs e) { if (!StringExt.IsNumeric(textBoxNrTelefon.Text) || !StringExt.IsNumeric(textBoxSumaDonatie.Text)) { MessageBox.Show("Nr Telefon / Suma trebuie sa fie un numar!"); return; } CazCaritabil currentCaz = (CazCaritabil)dataGridViewCazuri.CurrentRow.DataBoundItem; Donator currentDonator = null; if (dataGridViewDonatori.CurrentRow != null) { currentDonator = (Donator)dataGridViewDonatori.CurrentRow.DataBoundItem; } else { currentDonator = new Donator(generateDonatorId(), textBoxNume.Text, textBoxAdresa.Text, Int64.Parse(textBoxNrTelefon.Text)); try { ctr.saveDonator(currentDonator); } catch (ValidationException ex) { MessageBox.Show(ex.ToString()); } } int id = generateDonatieId(); Donatie donatie = new Donatie(id, currentDonator.Id, currentCaz.Id, Double.Parse(textBoxSumaDonatie.Text)); donatie.Id = id; try { ctr.donatieAdded(donatie); Double s = currentCaz.SumaTotala + Double.Parse(textBoxSumaDonatie.Text); ctr.updateSumaCaz(new CazCaritabil(currentCaz.Id, currentCaz.Denumire, s)); MessageBox.Show("Donatia a fost inregistrata! Va multumim!"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public ActionResult Edit([Bind(Include = "Id,IdUtilizator,Data,Centru,Oras,TipDonatie")] Donatie donatie) { try { donatie.IdUtilizator = User.Identity.GetUserId(); if (ModelState.IsValid) { db.Entry(donatie).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); } catch { return(View()); } }
public void save(Donatie entity) { log.InfoFormat("Entering save with entity {0}", entity); var con = DBUtils.getConnection(); using (var comm = con.CreateCommand()) { comm.CommandText = "insert into donatii values (@id, @idD, @idC, @suma)"; var paramId = comm.CreateParameter(); paramId.ParameterName = "@id"; paramId.Value = entity.Id; Console.WriteLine("44444444444444444444444444444" + entity.Id); comm.Parameters.Add(paramId); var paramIdD = comm.CreateParameter(); paramIdD.ParameterName = "@idD"; paramIdD.Value = entity.IdD; comm.Parameters.Add(paramIdD); var paramIdC = comm.CreateParameter(); paramIdC.ParameterName = "@idC"; paramIdC.Value = entity.IdC; comm.Parameters.Add(paramIdC); var paramSuma = comm.CreateParameter(); paramSuma.ParameterName = "@suma"; paramSuma.Value = entity.Suma; comm.Parameters.Add(paramSuma); var result = comm.ExecuteNonQuery(); if (result == 0) { throw new RepositoryException("No task added !"); } } log.Info("Exiting save - Donatie"); }
/* public void login(Angajat angajat, ITeledonObserver client) * { * if (angajat != null) * { * if (loggedClients.ContainsKey(angajat.username)) * throw new TeledonException("User already logged!"); * loggedClients.Add(angajat.username, client); * } * else throw new TeledonException("Authentication failed."); * }*/ public void donatieS(CazDTO caz, string numeDonator, string adresa, string nrTel, float sumaDonata) { lock (this) { handleDonatori(numeDonator, nrTel, adresa); Int32 id = getDonator(numeDonator, nrTel).Id; Int32 cazId = getCazId(caz); Donatie d = new Donatie(sumaDonata, id, cazId); try { validatorDonatii.valideaza(d); } catch (Exception e) { } donatiiDBRepository.save(d); float s = caz.SumaAdunata; s += sumaDonata; caz.SumaAdunata = s; notifyAllAngajatiDonatie(); } }
public void update(Donatie old, Donatie entity) { throw new NotImplementedException(); }
public void addDonatie(Donatie donatie) { donatieRepo.save(donatie); }
public void Add(Donatie entity) { _repository.Add(entity); }
public void InitializeTest() { _testDonatie = new Donatie(); }
private Response handleRequest(Request request) { Response response = null; if (request is GetCazuriRequest) { Console.WriteLine("GetCazuriRequest....."); GetCazuriRequest getReq = (GetCazuriRequest)request; try { CazCaritabil[] allCazuri; lock (server) { allCazuri = server.getCazuri(); } CazCaritabilDTO[] frDTO = DTOUtils.getDTO(allCazuri); return(new GetCazuriResponse(frDTO)); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is GetDonatiiRequest) { Console.WriteLine("GetDonatiiRequest....."); GetDonatiiRequest getReq = (GetDonatiiRequest)request; try { Donatie[] allDonatii; lock (server) { allDonatii = server.getDonatii(); } DonatieDTO[] frDTO = DTOUtils.getDTO(allDonatii); return(new GetDonatiiResponse(frDTO)); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is GetDonatoriRequest) { Console.WriteLine("GetDonatoriRequest....."); GetDonatoriRequest getReq = (GetDonatoriRequest)request; try { Donator[] allDonatori; lock (server) { allDonatori = server.getDonatori(); } DonatorDTO[] frDTO = DTOUtils.getDTO(allDonatori); return(new GetDonatoriResponse(frDTO)); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is LoginRequest) { Console.WriteLine("Login request ..."); LoginRequest logReq = (LoginRequest)request; VoluntarDTO udto = logReq.User; Voluntar user = DTOUtils.getFromDTO(udto); try { lock (server) { server.login(user, this); } return(new OkResponse()); } catch (MyException e) { connected = false; return(new ErrorResponse(e.Message)); } } if (request is LogoutRequest) { Console.WriteLine("Logout request"); LogoutRequest logReq = (LogoutRequest)request; VoluntarDTO udto = logReq.User; Voluntar user = DTOUtils.getFromDTO(udto); try { lock (server) { server.logout(user, this); } connected = false; return(new OkResponse()); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is SaveDonatorRequest) { Console.WriteLine("SaveDonatorRequest ..."); SaveDonatorRequest senReq = (SaveDonatorRequest)request; DonatorDTO mdto = senReq.Add; Donator message = DTOUtils.getFromDTO(mdto); try { lock (server) { server.addDonator(message); } return(new OkResponse()); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is SaveDonatieRequest) { Console.WriteLine("SaveDonatieRequest ..."); SaveDonatieRequest senReq = (SaveDonatieRequest)request; DonatieDTO mdto = senReq.Add; Donatie message = DTOUtils.getFromDTO(mdto); try { lock (server) { server.addDonatie(message); } return(new OkResponse()); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } if (request is UpdateCazRequest) { Console.WriteLine("UpdateCazRequest ..."); UpdateCazRequest upReq = (UpdateCazRequest)request; CazCaritabilDTO cazDTO = upReq.Caz; CazCaritabil caz = DTOUtils.getFromDTO(cazDTO); try { lock (server) { server.updateCazCaritabil(caz); } return(new OkResponse()); } catch (MyException e) { return(new ErrorResponse(e.Message)); } } return(response); }
public void donatieAdded(Donatie donatie) { server.addDonatie(donatie); }