public dynamic SaveMember( string name, string phone, string nationalid, string address, string Age, int jid, int GenderId ) { Member m = new Member(); m.FullName = name; m.GenderId = GenderId; m.Address = address; m.Age = Age; m.PhoneNo = phone; m.CityId = jid; m.NationalId = nationalid; m.IsDeleted = false; db.Members.Add(m); db.SaveChanges(); Session["Mid"] = m.ID; return(true); }
public ActionResult SaveComplaint(ComplainMember c) { MyProjectDBEntities db = new MyProjectDBEntities(); ComplainMember complainMember = new ComplainMember(); Complaint complaint = new Complaint(); Member member = new Member(); Gender gender = new Gender(); gender.GenderName = c.Gender.GenderName; member.FullName = c.Member.FullName; member.Age = c.Member.Age; complaint.AvialableRespondNotes = c.Complaint.AvialableRespondNotes; complaint.IsDeleted = false; complaint.ComplainDate = c.Complaint.ComplainDate; complaint.ComplaintDescription = c.Complaint.ComplaintDescription; if (Session["ComplaintFile"] != null) { List <string> ComplaintFiles = (List <string>)Session["ComplaintFile"]; complaint.ComplaintFilePath = ComplaintFiles[0]; Session.Remove("ComplaintFile"); } if (ModelState.IsValid) { //db.Entry(member).State = EntityState.Added; //db.Entry(gender).State = EntityState.Added; //db.Entry(complaint).State = EntityState.Added; db.Members.Add(member); db.Complaints.Add(complaint); db.Genders.Add(gender); db.SaveChanges(); return(RedirectToAction("Index")); } //if there error will view the ViewScreen Fulled with the corrupted object distributed throw the inputs return(View("AskDoctorData", c)); }
public dynamic Create(Pharamacy p) { if (ModelState.IsValid) { MyProjectDBEntities db = new MyProjectDBEntities(); var userid = User.Identity.GetUserId(); var member = db.Members.FirstOrDefault(x => x.UserId == userid); Pharamacy pharamacy = new Pharamacy(); pharamacy.IsDeleted = false; pharamacy.PharmacyAddress = p.PharmacyAddress; pharamacy.PharmacyName = p.PharmacyName; pharamacy.PharmacyPhone = p.PharmacyPhone; if (member != null) { pharamacy.PharmacyOwnerId = member.ID; } db.Pharamacies.Add(pharamacy); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(p)); }
public dynamic RequestMedicine(PharmacyMedicineRequest pmr) { if (ModelState.IsValid) { MyProjectDBEntities db = new MyProjectDBEntities(); PharmacyMedicineRequest pharmacyMedicineRequest = new PharmacyMedicineRequest(); pharmacyMedicineRequest.IsDeleted = false; pharmacyMedicineRequest.Amount = pmr.Amount; pharmacyMedicineRequest.MedicineId = pmr.MedicineId; pharmacyMedicineRequest.RequestPharamcyId = pmr.RequestPharamcyId; pharmacyMedicineRequest.RequestDate = DateTime.Now; pharmacyMedicineRequest.LatestRequestStatusId = 1; db.PharmacyMedicineRequests.Add(pharmacyMedicineRequest); db.SaveChanges(); PhMedicineRequestStatu requeststatus = new PhMedicineRequestStatu(); requeststatus.PhMedicineRequestId = pharmacyMedicineRequest.ID; requeststatus.StatusId = 1; requeststatus.StatusDate = DateTime.Now; db.PhMedicineRequestStatus.Add(requeststatus); db.SaveChanges(); } return(View(pmr)); }
public ActionResult Create(Medicine m) { if (ModelState.IsValid) { MyProjectDBEntities db = new MyProjectDBEntities(); Medicine medicine = new Medicine(); medicine.MedicineName = m.MedicineName; medicine.IsDeleted = false; medicine.ExpireDate = m.ExpireDate; medicine.MedicineDescription = m.MedicineDescription; db.Medicines.Add(medicine); db.SaveChanges(); return(RedirectToAction("RequestMedicine", "Pharmacy")); } return(View(m)); }
public async Task <ActionResult> Register(RegisterViewModel model) { MyProjectDBEntities db = new MyProjectDBEntities(); if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, PhoneNumber = model.Password }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (Session["RoleName"] != null) { string RoleName = Session["RoleName"].ToString(); await UserManager.AddToRoleAsync(user.Id, RoleName); Session.Remove("RoleName"); } await SignInManager.SignInAsync(user, false, false); if (Session["Mid"] != null) { int id = Convert.ToInt32(Session["Mid"].ToString()); Session.Remove("Mid"); var member = db.Members.Find(id); member.UserId = user.Id; db.Entry(member).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("index", "Home")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } return(View(model)); }
public List <string> SaveChanges() { List <string> errors = new List <string>(); try { context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { errors.Add("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage); } } } return(errors); }