示例#1
0
 /// <summary>
 /// Edit producer based on producer id
 /// </summary>
 /// <param name="model"></param>
 /// <param name="producerId"></param>
 /// <returns></returns>
 public ProducerModel EditProducer(ProducerModel model, long producerId)
 {
     model.Producer = db.tblProducers.Where(u => u.ProducerID == producerId).FirstOrDefault();
     if (model.Producer != null && model.Producer.ProducerID > 0)
     {
         model.Producer.FirstName      = model.FirstName;
         model.Producer.LastName       = model.LastName;
         model.Producer.DateOfBirth    = model.DateOfBirth;
         model.Producer.NumberOfMovies = (long)model.NumberOfMovies;
         db.SaveChanges();
     }
     return(model);
 }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <summary>
        /// Get all existing producers list from producers database table
        /// </summary>
        /// <param name="model"></param>
        /// <param name="sortingOrder"></param>
        /// <param name="sortingDir"></param>
        /// <param name="searchText"></param>
        /// <returns></returns>
        public ProducerModel GetAllProducers(ProducerModel model, string sortingOrder, string sortingDir, string searchText)
        {
            if (!string.IsNullOrEmpty(searchText))
            {
                model.Producers = db.tblProducers.Where(u => u.FirstName.ToLower().Contains(searchText.ToLower()) ||
                                                        u.LastName.ToLower().Contains(searchText.ToLower()) ||
                                                        u.NumberOfMovies == NumberOfMovies
                                                        ).ToList();
            }
            else
            {
                model.Producers = db.tblProducers.ToList();
            }

            switch (sortingOrder)
            {
            case "FirstName":
                if (sortingDir.ToLower().Equals("asc"))
                {
                    model.Producers = model.Producers.OrderBy(u => u.FirstName).ToList();
                }
                else
                {
                    model.Producers = model.Producers.OrderByDescending(u => u.FirstName).ToList();
                }
                break;

            case "LastName":
                if (sortingDir.ToLower().Equals("asc"))
                {
                    model.Producers = model.Producers.OrderBy(u => u.LastName).ToList();
                }
                else
                {
                    model.Producers = model.Producers.OrderByDescending(u => u.LastName).ToList();
                }
                break;

            case "DateOfBirth":
                if (sortingDir.ToLower().Equals("asc"))
                {
                    model.Producers = model.Producers.OrderBy(u => u.DateOfBirth).ToList();
                }
                else
                {
                    model.Producers = model.Producers.OrderByDescending(u => u.DateOfBirth).ToList();
                }
                break;

            case "NumberOfMovies":
                if (sortingDir.ToLower().Equals("asc"))
                {
                    model.Producers = model.Producers.OrderBy(u => u.NumberOfMovies).ToList();
                }
                else
                {
                    model.Producers = model.Producers.OrderByDescending(u => u.NumberOfMovies).ToList();
                }
                break;

            default:
                model.Producers = model.Producers.OrderByDescending(u => u.ProducerID).ToList();
                break;
            }

            return(model);
        }