public void UpdateProducer(Producer producer) { using (MoviesEntities db = new MoviesEntities()) { tblProducer tProducer = db.tblProducers.Where(q => q.ProducerId == producer._Id).FirstOrDefault(); UpdateEntity(ref tProducer, producer); db.SaveChanges(); } }
private void UpdateEntity(ref tblProducer tProducer, Producer producer) { tProducer.ProducerName = producer._Name; tProducer.Bio = producer._Bio; tProducer.DateOfBirth = producer._DateOfBirth; tProducer.IsDeleted = false; tProducer.GenderId = producer._SelectedGender; tProducer.LastModfiedDateTime = DateTime.Now; }
/// <summary> /// Add a new producer /// </summary> /// <param name="model"></param> /// <returns></returns> public long AddProducer(ProducerModel model) { long producerId = 0; tblProducer prd = new tblProducer(); prd.FirstName = model.FirstName; prd.LastName = model.LastName; prd.DateOfBirth = model.DateOfBirth; prd.NumberOfMovies = model.NumberOfMovies; db.tblProducers.Add(prd); db.SaveChanges(); producerId = prd.ProducerID; return(producerId); }
/// <summary> /// Get all available producers for dropdown selection /// </summary> /// <returns></returns> public IEnumerable <SelectListItem> GetProducers() { var var_Producer = new tblProducer(); var roles = db.tblProducers .ToList() .Select(x => new SelectListItem { Value = x.ProducerID.ToString(), Text = x.FirstName.ToString() + " " + x.LastName.ToString() }); return(new SelectList(roles, "Value", "Text")); }
public int DeleteProducer(decimal id) { using (MoviesEntities db = new MoviesEntities()) { var tProducer = db.tblMovies.Select(q => q.MovieId == id).ToList(); if (tProducer.Count == 0) { tblProducer tblProducer = db.tblProducers.Find(id); db.tblProducers.Remove(tblProducer); db.SaveChanges(); return(0); } return(-1); } }
public bool Create(Producer producer) { try { using (MoviesEntities db = new MoviesEntities()) { tblProducer tProducer = new tblProducer(); UpdateEntity(ref tProducer, producer); tProducer.CreatedDateTime = DateTime.Now; db.tblProducers.Add(tProducer); db.SaveChanges(); } return(true); } catch (Exception ex) { return(false); } }