Esempio n. 1
0
        public async Task <Response> RemoveLesson(string ID, string UserID, string ClientID)
        {
            try
            {
                if (CheckLogin(UserID, ClientID))
                {
                    var ourItem = _lessionService.CreateQuery().Find(o => o.ID == ID && o.CreateUser == UserID);
                    if (ourItem != null)
                    {
                        var childNote = _lessionPartService.CreateQuery().Find(o => o.ParentID == ID).ToList();
                        for (int i = 0; childNote != null && i < childNote.Count; i++)
                        {
                            var item  = childNote[0];
                            var media = _lessionExtendService.CreateQuery().Find(o => o.LessonPartID == item.ID).ToList();
                            if (media != null && media.Count > 0)
                            {
                                _fileProcess.DeleteFiles(media.Select(o => o.OriginalFile).ToList());
                                await _lessionExtendService.RemoveRangeAsync(media.Select(o => o.ID));
                            }
                            await _lessionPartService.RemoveAsync(item.ID);
                        }
                        await _lessionService.RemoveAsync(ID);

                        return(new Response(200, "Success get all", ID));
                    }
                    else
                    {
                        return(new Response(301, "Permission fails", ID));
                    }
                }
                else
                {
                    return(new Response(301, "Lỗi xác thực", null));
                }
            }
            catch (Exception ex)
            {
                await _logs.WriteLogsError("CreateOrUpdateLesson", ex);

                return(new Response(500, ex.Message, null));
            }
        }