Exemple #1
0
        public Work Save(int id, string Title, string Description, string Url, WorkType WorkType, int UserId, DateTime DateSubmitted, bool PartcipateInPoll, bool ApprovedForPoll, bool Live, bool Featured, int PollId)
        {
            var work = id > 0 ? GetById(id) : new Work();

            if(!string.IsNullOrEmpty(Url))
            {
                Url = Assets.HasHttpOrHttps(Url) ? Url : string.Format("http://{0}", Url);
            }

            work.Title = Title;
            work.Description = Description;
            work.Url =  Url;
            work.WorkType = (int)WorkType;
            work.UserId = UserId;
            work.DateSubmitted = id > 0 ? work.DateSubmitted : DateSubmitted;
            work.PartcipateInPoll = PartcipateInPoll;
            work.ApprovedForPoll = ApprovedForPoll;
            work.Live = Live;
            work.Featured = Featured;
            work.PollId = PollId;
            work.Views = id > 0 ? work.Views : 0;

            var workDa = new WorkDa(databasecontext);

            //if new
            if (id < 1) work = workDa.Add(work);
            //update
            else work = workDa.Update(work);

            return work;
        }
Exemple #2
0
 public Work GetById(int id)
 {
     Work work = new WorkDa(databasecontext).GetById(id);
     //work.Photos = PhotoBl.GetList(work.Id, PhotoType.Work);
     work.UrlPath = String.Format("/{0}/{1}/{2}", Enum.GetName(typeof(WorkType), work.WorkType).ToLower(), Assets.SanitiseForUrlPath(work.Title), work.Id);
     work.User = UserBl.GetUserById(work.UserId);
     return work;
 }
Exemple #3
0
        public void Delete(int id)
        {
            var work = new WorkDa(databasecontext);
            if (id > 0)
            {
                var currentWork = GetById(id);                
                work.Delete(currentWork);

                //delete images
                if (PhotoBl.GetList(currentWork.Id).Count > 0)
                {
                    foreach (var photo in PhotoBl.GetList(currentWork.Id))
                    {
                        new PhotoBl().Delete(photo.Id);
                    }                    
                }
               
            }
        }