Example #1
0
        //Kiểm tra object truyền vào có tên trùng trong database không
        //KQ: false: TenTacGia bị trùng, true: cập nhật thành công
        public ResponseDetails UpdatePhuLuc(IEnumerable <PhuLuc> phuLucs)
        {
            foreach (var phuLuc in phuLucs)
            {
                /*Bắt lỗi [ID]*/
                var truyenRepo  = new TruyenRepository(_context);
                var theLoaiRepo = new TheLoaiRepository(_context);

                if (!truyenRepo.FindByCondition(t => t.TruyenID.Equals(phuLuc.TruyenID)).Any())
                {
                    return(new ResponseDetails()
                    {
                        StatusCode = ResponseCode.Error,
                        Message = "ID truyện không tồn tại",
                        Value = phuLuc.TruyenID.ToString()
                    });
                }
                if (!theLoaiRepo.FindByCondition(t => t.TheLoaiID.Equals(phuLuc.TheLoaiID)).Any())
                {
                    return(new ResponseDetails()
                    {
                        StatusCode = ResponseCode.Error,
                        Message = "ID thể loại không tồn tại",
                        Value = phuLuc.TheLoaiID.ToString()
                    });
                }
                /*End*/

                //Nếu phụ lục nhập vào chưa có
                if (!FindByCondition(m => m.TheLoaiID == phuLuc.TheLoaiID && m.TruyenID == phuLuc.TruyenID).Any())
                {
                    Create(phuLuc);
                }
                else
                {
                    Update(phuLuc);
                }
            }

            return(new ResponseDetails()
            {
                StatusCode = ResponseCode.Success, Message = "Sửa phụ lục thành công"
            });
        }
Example #2
0
        //Kiểm tra collection truyền vào có tên trùng trong database không
        //KQ: false = TruyenID hoặc TheLoaiID không tồn tại, true: thêm thành công
        public ResponseDetails CreatePhuLuc(IEnumerable <PhuLuc> phuLucs)
        {
            foreach (var phuLuc in phuLucs)
            {
                /*Bắt lỗi [ID]*/
                var truyenRepo  = new TruyenRepository(_context);
                var theLoaiRepo = new TheLoaiRepository(_context);

                if (!truyenRepo.FindByCondition(t => t.TruyenID.Equals(phuLuc.TruyenID)).Any())
                {
                    return(new ResponseDetails()
                    {
                        StatusCode = ResponseCode.Error,
                        Message = "ID truyện không tồn tại",
                        Value = phuLuc.TruyenID.ToString()
                    });
                }
                if (!theLoaiRepo.FindByCondition(t => t.TheLoaiID.Equals(phuLuc.TheLoaiID)).Any())
                {
                    return(new ResponseDetails()
                    {
                        StatusCode = ResponseCode.Error,
                        Message = "ID thể loại không tồn tại",
                        Value = phuLuc.TheLoaiID.ToString()
                    });
                }
                if (FindByCondition(m => m.TheLoaiID == phuLuc.TheLoaiID && m.TruyenID == phuLuc.TruyenID).Any())
                {
                    return(new ResponseDetails()
                    {
                        StatusCode = ResponseCode.Error,
                        Message = "Truyện này đã tồn tại thể loại này",
                        Value = "ID truyện: " + phuLuc.TruyenID + "/ ID thể loại: " + phuLuc.TheLoaiID.ToString()
                    });
                }
                /*End*/

                Create(phuLuc);
            }
            return(new ResponseDetails()
            {
                StatusCode = ResponseCode.Success
            });
        }