public async Task <ActionResult <bool> > Post(tbl_patient model) { try { string dossier = string.Empty; IEnumerable <tbl_patient> lst = await GetAll(); if (lst.Count() > 0) { dossier = (Convert.ToInt64(lst.Max(c => c.DossierNumberPermanent)) + 1).ToString().PadLeft(6, '0'); } else { dossier = "000001"; } model.DossierNumberPermanent = dossier; await repository.Add(model); return(true); } catch (Exception) { return(false); } }
public async Task <ActionResult <bool> > Post(tblReception model) { try { ContextDb db = new ContextDb(); model.Id = 0; tbl_patient patient = model.tbl_patient; if (patient.Id <= 0) { string dossier = string.Empty; if (db.tbl_patient.Count() > 0) { dossier = (Convert.ToInt64(db.tbl_patient.Max(c => c.DossierNumberPermanent)) + 1).ToString().PadLeft(6, '0'); } else { dossier = "000001"; } patient.DossierNumberPermanent = dossier; db.tbl_patient.Add(patient); } else { db.Entry(patient).State = EntityState.Modified; } db.SaveChanges(); model.IdPatient = patient.Id; model.tbl_patient = null; model.IdWaiting = 4; model.RegDate = MYHelper.GetDate(); model.IdGeneralGroup = 1; var service = db.tbl_Service.Find(model.IdService); model.tblVisits.ToList().ForEach(c => { c.Id = 0; c.IdWaiting = 4; c.DateRequest = MYHelper.GetDate(); c.IdReception = model.Id; c.VisitDate = MYHelper.GetDate(c.FarsiDate); c.Count = 1; c.Percents = 100; c.FreePrices = service.FreePrices; c.Tariff = service.FreePrices; }); await repository.Add(model); return(true); } catch (Exception err) { return(false); } }
public async Task <ActionResult <bool> > Put(long id, tbl_patient model) { if (id != model.Id) { return(BadRequest()); } try { await repository.Update(model); return(true); } catch (DbUpdateConcurrencyException) { return(false); } }