//----------------------------------------------------------- //Выбираем продукт по идшнику public Care GetProductById(int ProductId) { Care obj = context.Cares.FirstOrDefault(product => product.ProductId == ProductId); obj.Colors = new List <Color>(); return(obj); }
//------------------------------------------------------ //Удаление товара public ActionResult DeleteProduct(int ProductId, int CategoryId) { if (CategoryId == 1) { Parfum obj = productrepo.GetProductById(ProductId); productrepo.DeleteProduct(obj); TempData["message"] = String.Format("Товар '{0}' удален из базы", obj.ProductName); return(RedirectToAction("ShowProductsInCategory", "Admin", new { obj.CategoryId })); } else if (CategoryId == 2) { Cosmetic obj = cosmeticrepo.GetProductById(ProductId); cosmeticrepo.DeleteProduct(obj); TempData["message"] = String.Format("Товар '{0}' удален из базы", obj.ProductName); return(RedirectToAction("ShowProductsInCategory", "Admin", new { obj.CategoryId })); } else if (CategoryId == 3) { Care obj = carerepo.GetProductById(ProductId); carerepo.DeleteProduct(obj); TempData["message"] = String.Format("Товар'{0}'удвлен из базы", obj.ProductName); return(RedirectToAction("ShowProductsInCategory", "Admin", new { obj.CategoryId })); } return(View()); }
//---------------------------------------------------------- //---------------------------------------------------------- //Метод по добавлению нового товара и по сохранению изменений в существующих public void SaveProduct(Care obj) { if (obj.ProductId == 0) { context.Cares.Add(obj); } else { Care prod = context.Cares.Find(obj.ProductId); if (prod != null) { prod.ProductName = obj.ProductName; prod.CategoryId = obj.CategoryId; prod.NewPrice = obj.NewPrice; prod.Description = obj.Description; prod.Type = obj.Type; if (obj.ImageMimeType != null && obj.ImageData != null) { prod.ImageData = obj.ImageData; prod.ImageMimeType = obj.ImageMimeType; } } } context.SaveChanges(); }
//------------------------------------------------------ //Редактирование средств по уходу public ActionResult EditCare(int ProductId) { Care care = carerepo.GetProductById(ProductId); CareViewModel obj = Mapper.Map <CareViewModel>(care); return(View(obj)); }
public IHttpActionResult PostCare(Care care) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Cares.Add(care); try { db.SaveChanges(); } catch (DbUpdateException) { if (CareExists(care.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = care.Id }, care)); }
public IHttpActionResult PutCare(int id, Care care) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != care.Id) { return(BadRequest()); } db.Entry(care).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CareExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> Edit(int id, [Bind("CareId,CareCode,FirstName,OtherName,LastName,Name,Phone,DateCreated,DateUpdated,Passport")] Care care) { if (id != care.CareId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(care); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CareExists(care.CareId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(care)); }
public async Task <ActionResult <Care> > PostCare(Care care) { _context.Care.Add(care); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCare", new { id = care.CareId }, care)); }
public async Task <IActionResult> PutCare(int id, Care care) { if (id != care.CareId) { return(BadRequest()); } _context.Entry(care).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CareExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("CareId,CareCode,FirstName,OtherName,LastName,Name,Phone,DateCreated,DateUpdated,Passport")] Care care) { if (ModelState.IsValid) { _context.Add(care); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(care)); }
//----------------------------------------- //Изменение доступности товара public void ChangeAvailability(int productId, bool isAvailable) { Care obj = GetProductById(productId); foreach (var item in obj.Colors) { context.Entry(item).State = EntityState.Modified; } obj.IsAvailable = isAvailable; context.SaveChanges(); }
//----------------------------------------- //Добавление просмотра public void AddCountOfView(int productId) { Care obj = GetProductById(productId); foreach (var item in obj.Colors) { context.Entry(item).State = EntityState.Modified; } obj.CountOfView += 1; context.SaveChanges(); }
public IHttpActionResult DeleteCare(int id) { Care care = db.Cares.Find(id); if (care == null) { return(NotFound()); } db.Cares.Remove(care); db.SaveChanges(); return(Ok(care)); }
public void InsertCare(Care care) { Disease d = GetDiseases().Find(p => p.ID == care.Disease_Id); //乳房类:137,蹄类174 if (d.DiseaseTypeID == 137 || d.DiseaseTypeID == 174) { medicalDAL.InsertCare(care, true); } else { medicalDAL.InsertCare(care, false); } }
public FileContentResult GetImage(int ProductId, int CategoryId) { if (CategoryId == 1) { Parfum obj = productrepo.GetProductById(ProductId); if (obj != null) { return(File(obj.ImageData, obj.ImageMimeType)); } else { return(null); } } else if (CategoryId == 2) { Cosmetic obj = cosmeticrepo.GetProductById(ProductId); if (obj != null) { return(File(obj.ImageData, obj.ImageMimeType)); } else { return(null); } } else if (CategoryId == 3) { Care obj = carerepo.GetProductById(ProductId); if (obj != null) { return(File(obj.ImageData, obj.ImageMimeType)); } else { return(null); } } return(null); }
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { ObservableCollection <Care> caresearch = new ObservableCollection <Care>(); caresearch.Clear(); carelist1.ItemsSource = caresearch; //carelist.Items.Clear(); Care findcare = new Care(); string txt = txtbSearchCare.Text; findcare = careCollection.Where(x => x.careName == txtbSearchCare.Text).FirstOrDefault(); if (findcare != null) { caresearch.Clear(); caresearch.Add(findcare); carelist1.ItemsSource = caresearch; } }
public void InsertCare(Care care, bool isBeastOrFoot) { string sql; if (isBeastOrFoot) { sql = string.Format(@"insert into Medical_Care(EarNum,Disease_Id,Prescription,DoctorID,Date,LeftFront,RightFront,RightBack,LeftBack) values ({0},{1},'{2}',{3},'{4}',{5},{6},{7},{8})", care.EarNum, care.Disease_Id, care.Prescription, care.DoctorID, DateTime.Now.ToShortDateString(), care.LeftFront, care.RightFront, care.LeftBack, care.RightBack); } else { sql = string.Format(@"insert into Medical_Care(EarNum,Disease_Id,Prescription,DoctorID,Date) values ({0},{1},'{2}',{3},'{4}')", care.EarNum, care.Disease_Id, care.Prescription, care.DoctorID, DateTime.Now.ToShortDateString()); } dataProvider1mutong.ExecuteNonQuery(sql, CommandType.Text); }
public ActionResult AddCare(CareViewModel obj, HttpPostedFileBase Image) { if (ModelState.IsValid) { if (Image != null) { obj.ImageMimeType = Image.ContentType; obj.ImageData = new byte[Image.ContentLength]; Image.InputStream.Read(obj.ImageData, 0, Image.ContentLength); } Care prod = Mapper.Map <Care>(obj); carerepo.SaveProduct(prod); TempData["message"] = String.Format("Товар '{0}' добавлен", obj.ProductName); return(RedirectToAction("Categories", "Admin")); } else { return(View(obj)); } }
public ActionResult EditCare(CareViewModel obj, HttpPostedFileBase Image) { if (ModelState.IsValid) { if (Image != null) { obj.ImageMimeType = Image.ContentType; obj.ImageData = new byte[Image.ContentLength]; Image.InputStream.Read(obj.ImageData, 0, Image.ContentLength); } Care p = Mapper.Map <Care>(obj); carerepo.SaveProduct(p); TempData["message"] = String.Format("Изменения в товаре '{0}' сохранены", obj.ProductName); return(RedirectToAction("ShowProductsInCategory", "Admin", new { obj.CategoryId })); } else { return(View(obj)); } }
public ObservableCollection <Care> GetAllCare(int id) { ObservableCollection <Care> carecollection = new ObservableCollection <Care>(); string uriPath = "file:///C:/CM/Patients/" + id; string localPath = new Uri(uriPath).LocalPath; bool exists = Directory.Exists(localPath); if (exists) { List <string> lstFileNames = new List <string>(Directory.EnumerateFiles(localPath, "care.json")); foreach (string fileName in lstFileNames) { string json; json = File.ReadAllText(fileName); var objects = JArray.Parse(json); foreach (JObject root in objects) { if (root.HasValues) { Care care = new Care(); care.careId = (int)root["careId"]; care.careName = (string)root["careName"]; care.carePic1 = (string)root["carePic1"]; care.carePic2 = (string)root["carePic2"]; care.careFunction = (string)root["careFunction"]; care.carePrescriptor = (string)root["carePrescriptor"]; care.carePoso = (string)root["carePoso"]; care.careDuring = (string)root["careDuring"]; care.careEndDate = (string)root["careEndDate"]; care.careSecondaryEffect = (string)root["careSecondaryEffect"]; care.careComplementaryInfo = (string)root["careComplementaryInfo"]; carecollection.Add(care); } } } } return(carecollection); }
public JsonResult InsertCare() { Care c = new Care(); c.DisplayEarNum = Request.Form["DisplayEarNum"]; c.Disease_Id = Convert.ToInt32(Request.Form["diseases"]); c.Prescription = Request.Form["Prescription"]; c.Date = DateTime.Now; c.LeftFront = Convert.ToInt32(Request.Form["pLeftFront"]); c.RightFront = Convert.ToInt32(Request.Form["pRightFront"]); c.LeftBack = Convert.ToInt32(Request.Form["pLeftBack"]); c.RightBack = Convert.ToInt32(Request.Form["pRightBack"]); c.EarNum = CowBLL.ConvertDislayEarNumToEarNum(c.DisplayEarNum, UserBLL.Instance.CurrentUser.Pasture.ID); c.DoctorID = UserBLL.Instance.CurrentUser.ID; bllMedical.InsertCare(c); CowBLL bllCow = new CowBLL(); bllCow.UpdateCowIllStatus(c.EarNum, true); return(Json(new { Result = 1 }, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Create([FromBody] Care care) { await _context.CreateNewCareAsync(care); return(Ok(care.Id)); }
//---------------------------------------------------------- //---------------------------------------------------------- //Удаление товара public void DeleteProduct(Care obj) { context.Cares.Remove(obj); context.SaveChanges(); }
public void AddCareToCareCollection(Care care) { careCollection.Add(care); }
public async Task CreateNewCareAsync(Care care) { care.OpenTime = DateTime.Now; await _careCollection.InsertOneAsync(care); }
private void SaveCare() { Care oldcare = new Care(); oldcare = careCollection.Where(x => x.careId == currentCare).FirstOrDefault(); if (oldcare != null) { string hashcode = txtbName.Text + txtbLastName.Text; int code = hashcode.GetHashCode(); oldcare.careId = code; oldcare.careName = txtbCareName.Text; oldcare.careFunction = txtbCareFunction.Text; oldcare.carePrescriptor = txtbPrescriptor.Text; oldcare.carePoso = txtbPoso.Text; oldcare.careDuring = txtbCareDuring.Text; oldcare.careEndDate = txtbCareEnd.Text; oldcare.careSecondaryEffect = txtbSecondaryEffects.Text; oldcare.careComplementaryInfo = txtbComplementaryInfo.Text; DateTime compared = new DateTime(); compared = Convert.ToDateTime("0001-01-01T00:00:00"); string subPath = @"c:\CM\Patients\" + currentUser.ToString() + "\therapists" + oldcare.careId; bool exists = Directory.Exists(subPath); if (!exists) { Directory.CreateDirectory(subPath); } string imgpath = @"c:\CM\Patients\" + currentUser.ToString() + "\therapists" + oldcare.careId + " " + Guid.NewGuid() + ".png"; if (imgPhoto.Source != null) { SaveToPng(imgPhoto, imgpath); } oldcare.carePic1 = imgpath; therapistCollection.Clear(); AddCareToCareCollection(oldcare); SaveCollectionToFile(therapistCollection, @"c:\CM\Patients\" + currentUser.ToString() + "\\" + oldcare.careId + ".json"); } else { Care newcare = new Care(); string hashcode = txtbName.Text + txtbLastName.Text; int code = hashcode.GetHashCode(); newcare.careId = code; newcare.careName = txtbCareName.Text; newcare.careFunction = txtbCareFunction.Text; newcare.carePrescriptor = txtbPrescriptor.Text; newcare.carePoso = txtbPoso.Text; newcare.careDuring = txtbCareDuring.Text; newcare.careEndDate = txtbCareEnd.Text; newcare.careSecondaryEffect = txtbSecondaryEffects.Text; newcare.careComplementaryInfo = txtbComplementaryInfo.Text; //newTherapist.patientsList.Add(currentUser.ToString());e DateTime compared = new DateTime(); compared = Convert.ToDateTime("0001-01-01T00:00:00"); //if (newcare.therapistCreationDate == compared) //{ // newcare.therapistCreationDate = DateTime.Now; //} //newTherapist.therapistLastModificationDate = DateTime.Now; string subPath = @"c:\CM\Patients\" + currentUser.ToString() + "\\" + newcare.careId; bool exists = Directory.Exists(subPath); if (!exists) { Directory.CreateDirectory(subPath); } string imgpath = @"c:\CM\Patients\" + currentUser.ToString() + "\\" + newcare.careName + " " + Guid.NewGuid() + ".png"; string imgpath2 = @"c:\CM\Patients\" + currentUser.ToString() + "\\" + newcare.careName + " " + Guid.NewGuid() + ".png"; if (imgPhoto1.Source != null) { SaveToPng(imgPhoto1, imgpath); } if (imgPhoto2.Source != null) { SaveToPng(imgPhoto2, imgpath2); } newcare.carePic1 = imgpath; newcare.carePic2 = imgpath2; AddCareToCareCollection(newcare); SaveCollectionToFile(careCollection, @"c:\CM\Patients\" + currentUser.ToString() + "\\care.json"); careCollection.Clear(); } }