コード例 #1
0
        public async Task <int> DeleteExhibitIntTopic(int exhibitId)
        {
            int rs = 0;
            //lấy obj trong bảng exhibitInTopic chứa topicId và exhibitId đó
            ExhibitInTopic exhibitInTopic = _unitOfWork.Repository <ExhibitInTopic>().GetAll()
                                            .Where(e => e.Status == true && e.ExhibitId == exhibitId).FirstOrDefault();

            if (exhibitInTopic != null)
            {
                //lấy topic ra
                Topic topic = _unitOfWork.Repository <Topic>().GetAll().Where(t => t.Id == exhibitInTopic.TopicId).FirstOrDefault();
                try
                {
                    //Delete row trong bảng ExhibitInTopic
                    _unitOfWork.Repository <ExhibitInTopic>().Delete(exhibitInTopic);

                    //Get exhibit đó ra để set status thành Ready
                    Exhibit exhibit = _unitOfWork.Repository <Exhibit>().GetById(exhibitId);
                    exhibit.Status = (int)ExhibitsStatus.Status.Ready;


                    _unitOfWork.Repository <Exhibit>().Update(exhibit, exhibit.Id);
                    await _unitOfWork.CommitAsync();


                    //xét trong bảng exhibitInTopic
                    var exhibitInTopicList = _unitOfWork.Repository <ExhibitInTopic>().GetAll()
                                             .Where(t => t.Status == true && t.TopicId == topic.Id).AsQueryable();

                    //nếu k còn obj nào trong topic đó thì set status cho topic đó về New
                    if (exhibitInTopicList.ToList().Count == 0)
                    {
                        topic.Status = (int)TopicStatus.Status.New;
                        _unitOfWork.Repository <Topic>().Update(topic, topic.Id);
                    }


                    await _unitOfWork.CommitAsync();

                    rs = 1;
                    return(rs);
                }
                catch (Exception)
                {
                    throw new Exception("Can not delete exhibit in this topic!!!");
                }
            }
            return(rs);
        }
コード例 #2
0
        public async Task <int> AddExhibitToTopic(int topicId, int exhibitId)
        {
            int rs = 0;

            Topic topic = _unitOfWork.Repository <Topic>().GetById(topicId);

            DateTime dt    = Convert.ToDateTime(DateTime.Now);
            string   s2    = dt.ToString("yyyy-MM-dd");
            DateTime dtnew = Convert.ToDateTime(s2);

            Exhibit exhibit = _unitOfWork.Repository <Exhibit>().GetById(exhibitId);


            ExhibitInTopic exhibitInTopic = new ExhibitInTopic
            {
                ExhibitId  = exhibit.Id,
                TopicId    = topicId,
                CreateDate = dtnew,
                Status     = true
            };

            try
            {
                await _unitOfWork.Repository <ExhibitInTopic>().InsertAsync(exhibitInTopic);

                await _unitOfWork.CommitAsync();

                exhibit.Status = (int)ExhibitsStatus.Status.Added;
                _unitOfWork.Repository <Exhibit>().Update(exhibit, exhibit.Id);

                if (topic.Status == (int)TopicStatus.Status.New)
                {
                    topic.Status = (int)TopicStatus.Status.Waiting;
                    _unitOfWork.Repository <Topic>().Update(topic, topic.Id);
                }

                await _unitOfWork.CommitAsync();

                rs = 1;
                return(rs);
            }
            catch (Exception)
            {
                throw new Exception("Add Exhibit To Topic Error!!!");
            }
        }
コード例 #3
0
        public String GetTopicOrEventContainExhibit(int exhibitId)
        {
            string         rs = "Hiện vật này không thuộc Chủ đề hay Sự kiện nào!";
            ExhibitInTopic topicContainExhibit = _unitOfWork.Repository <ExhibitInTopic>().GetAll().Where(t => t.ExhibitId == exhibitId && t.Status == true).FirstOrDefault();

            if (topicContainExhibit != null)
            {
                rs = "Hiện vật này đang thuộc về Chủ đề: " + topicContainExhibit.Topic.Name.ToString();
                return(rs.ToString());
            }

            ExhibitInEvent eventContainExhibit = _unitOfWork.Repository <ExhibitInEvent>().GetAll().Where(e => e.ExhibitId == exhibitId && e.Status == true).FirstOrDefault();

            if (eventContainExhibit != null)
            {
                rs = "Hiện vật này đang thuộc về Sự kiện: " + eventContainExhibit.Event.Name.ToString();
                return(rs.ToString());
            }
            return(rs.ToString());
        }