public HttpResponseMessage UpdateProducer([FromUri] string producerId, [FromBody] producer pr) { producer prod = null; Guid producerIdGuid = new Guid(producerId); using (movieBucketEntities entity = new movieBucketEntities()) { try { prod = entity.producers.Where(m => m.producer_id == producerIdGuid).FirstOrDefault(); if (prod == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Producer Detail not found In Database, Please Add new Detail !!!")); } prod.bio = pr.bio; prod.date_of_birth = pr.date_of_birth; prod.name = pr.name; prod.sex = pr.sex; prod.Movies = pr.Movies; entity.SaveChanges(); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)); } return(Request.CreateResponse(HttpStatusCode.OK, prod)); } }
public ActionResult DeleteConfirmed(byte id) { producer producer = db.producer.Find(id); db.producer.Remove(producer); db.SaveChanges(); return(RedirectToAction("Index")); }
public EmptyResult AddNewVideo() { video video = new video(); int video_id = (from m in db.video select m.video_id).ToList().Last() + 1; video.video_id = video_id; video.video_name = Request["name"]; video.video_year = Int32.Parse(Request["year"]); video.video_description = Request["description"]; video.video_price_per_day = Double.Parse(Request["price"]); video.video_country = Request["country"]; video.video_quantity = Int32.Parse(Request["quantity"]); db.video.Add(video); db.SaveChanges(); string [] genre = Request["genre"].Split(','); int videoGenreId = (from m in db.videogenre select m.videogenre_id).ToList().Last(); for (int i = 0; i < genre.Length; i++) { videogenre videoGenre = new videogenre(); videoGenre.videogenre_id = ++videoGenreId; videoGenre.videogenre_id_video = video_id; videoGenre.videogenre_id_genre = Int32.Parse(genre[i]); db.videogenre.Add(videoGenre); db.SaveChanges(); } string producer = Request["producer"]; producer findProducer = db.producer.FirstOrDefault(p => p.producer_name == producer); videoproducer vp = new videoproducer(); vp.videoproducer_id = (from m in db.videoproducer select m.videoproducer_id).ToList().Last() + 1; vp.videoproducer_id_video = video_id; if (findProducer == null) { producer pr = new producer(); int id = (from m in db.producer select m.producer_id).ToList().Last() + 1; pr.producer_id = id; pr.producer_name = producer; db.producer.Add(pr); db.SaveChanges(); vp.videoproducer_id_producer = id; } else { vp.videoproducer_id_producer = findProducer.producer_id; } db.videoproducer.Add(vp); db.SaveChanges(); return(new EmptyResult()); }
public ActionResult Edit([Bind(Include = "Producer_Id,Producer_name,Sex,Date_Of_Birth,Bio")] producer producer) { if (ModelState.IsValid) { db.Entry(producer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(producer)); }
public ActionResult Create([Bind(Include = "Producer_Id,Producer_name,Sex,Date_Of_Birth,Bio")] producer producer) { if (ModelState.IsValid) { db.producers.Add(producer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(producer)); }
public void SaveNewItem() { try { using (var db = new course_work_Entities()) { var pcTypeS = from p in db.pc_type where p.name.Equals(pcTypeField.Text) select p; pc_type pcType; if (!pcTypeS.Any()) { pcType = new pc_type() { name = pcTypeField.Text, }; db.pc_type.Add(pcType); db.SaveChanges(); } else { pcType = pcTypeS.First(); } var producerS = from p in db.producers where p.name.Equals(producerField.Text) select p; producer producer; if (!producerS.Any()) { producer = new producer() { name = producerField.Text, }; db.producers.Add(producer); db.SaveChanges(); } else { producer = producerS.First(); } var pc = new pc() { name = nameField.Text, description = descriptionField.Text, pc_type1 = pcType, producer1 = producer }; db.pcs.Add(pc); db.SaveChanges(); Init(); } list.SelectedIndex = list.Items.Count - 1; } catch (Exception) { MessageBox.Show("Щось пішло не так", "Помилка"); } }
// GET: Producers/Edit/5 public ActionResult Edit(byte?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } producer producer = db.producer.Find(id); if (producer == null) { return(HttpNotFound()); } return(View(producer)); }
/// <summary> /// Initializes a new instance of the <see cref="ProducerDTO"/> class /// </summary> /// <param name="producer">A <see cref="producer"/> containing deserialized response from 'available producers' endpoint</param> internal ProducerDTO(producer producer) { Guard.Argument(producer, nameof(producer)).NotNull(); Id = (int)producer.id; Name = producer.name; Description = producer.description; Active = producer.active; Url = producer.api_url; ScopeNames = string.IsNullOrEmpty(producer.scope) ? null : producer.scope.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries); StatefulRecoveryWindow = producer.stateful_recovery_window_in_minutes; }
public HttpResponseMessage PutProducer([FromBody] producer prod) { prod.producer_id = Guid.NewGuid(); using (movieBucketEntities entity = new movieBucketEntities()) { try { entity.producers.Add(prod); entity.SaveChanges(); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)); } return(Request.CreateResponse(HttpStatusCode.Accepted)); } }
public ActionResult Edit([Bind(Include = "id,first_name,last_name,dob,movies_produced,net_worth,about,profile")] producer producer, HttpPostedFileBase profile) { if (ModelState.IsValid) { if (profile != null) { string pic = System.IO.Path.GetFileName(profile.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/media/producerImage"), pic); // file is uploaded producer.profile = profile.FileName; profile.SaveAs(path); } db.Entry(producer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(producer)); }
public void SaveNewItem() { try { using (var db = new course_work_Entities()) { var s = from p in db.producers where p.name.Equals(producerField.Text) select p; producer producer; if (!s.Any()) { producer = new producer() { name = producerField.Text, }; db.producers.Add(producer); db.SaveChanges(); } else { producer = s.First(); } var component = new component() { name = nameField.Text, description = descriptionField.Text, category1 = (from c in db.categories where c.name.Equals(categoryField.Text) select c).First(), producer1 = producer, price = decimal.Parse(priceField.Text) }; db.components.Add(component); db.SaveChanges(); Init(); } list.SelectedIndex = list.Items.Count - 1; } catch (FormatException) { MessageBox.Show("Очікується число", "Помилка введення"); } catch (Exception) { MessageBox.Show("Щось пішло не так", "Помилка"); } }
public HttpResponseMessage GetProducer(string producerId) { producer prod = null; Guid producerIdGuid = new Guid(producerId); using (movieBucketEntities entity = new movieBucketEntities()) { try { prod = entity.producers.Where(m => m.producer_id == producerIdGuid).FirstOrDefault(); if (prod == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Producer data not available")); } } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)); } return(Request.CreateResponse(HttpStatusCode.OK, prod)); } }
public void SaveItem() { try { var index = list.SelectedIndex; using (var db = new course_work_Entities()) { var s = from p in db.producers where p.name.Equals(producerField.Text) select p; producer producer; if (!s.Any()) { producer = new producer() { name = producerField.Text, }; db.producers.Add(producer); db.SaveChanges(); } else { producer = s.First(); } var components = (from c in db.components select c).ToArray(); var component = components[index]; var deleteFlag = true; foreach (var c in components) { if (!c.Equals(component) && c.producer1.name.Equals(component.producer1.name)) { deleteFlag = false; } } var pcs = (from p in db.pcs select p).ToArray(); foreach (var p in pcs) { if (p.producer1.name.Equals(component.producer1.name)) { deleteFlag = false; } } if (deleteFlag) { db.producers.Remove(component.producer1); } component.name = nameField.Text; component.description = descriptionField.Text; component.category1 = (from c in db.categories where c.name.Equals(categoryField.Text) select c).First(); component.producer1 = producer; component.price = decimal.Parse(priceField.Text); db.SaveChanges(); Init(); } list.SelectedIndex = index; } catch (FormatException) { MessageBox.Show("Очікується число", "Помилка введення"); } catch (Exception) { MessageBox.Show("Щось пішло не так", "Помилка"); } }
public void SaveItem() { try { var index = list.SelectedIndex; using (var db = new course_work_Entities()) { var pcTypeS = from p in db.pc_type where p.name.Equals(pcTypeField.Text) select p; pc_type pcType; if (!pcTypeS.Any()) { pcType = new pc_type() { name = pcTypeField.Text, }; db.pc_type.Add(pcType); db.SaveChanges(); } else { pcType = pcTypeS.First(); } var producerS = from p in db.producers where p.name.Equals(producerField.Text) select p; producer producer; if (!producerS.Any()) { producer = new producer() { name = producerField.Text, }; db.producers.Add(producer); db.SaveChanges(); } else { producer = producerS.First(); } var pcs = (from p in db.pcs select p).ToArray(); var pc = pcs[index]; var deleteFlag = true; foreach (var p in pcs) { if (!p.Equals(pc) && p.pc_type1.name.Equals(pc.pc_type1.name)) { deleteFlag = false; } } if (deleteFlag) { db.pc_type.Remove(pc.pc_type1); } deleteFlag = true; foreach (var p in pcs) { if (!p.Equals(pc) && p.producer1.name.Equals(pc.producer1.name)) { deleteFlag = false; } } var components = (from c in db.components select c).ToArray(); foreach (var c in components) { if (c.producer1.name.Equals(pc.producer1.name)) { deleteFlag = false; } } if (deleteFlag) { db.producers.Remove(pc.producer1); } pc.name = nameField.Text; pc.description = descriptionField.Text; pc.pc_type1 = pcType; pc.producer1 = producer; db.SaveChanges(); Init(); } list.SelectedIndex = index; } catch (Exception) { MessageBox.Show("Щось пішло не так", "Помилка"); } }