public async Task <ActionResult> SetIndexSections(IndexSectionsModel ism)
        {
            try
            {
                IndexBoxInfoModel BoxInfo = ((List <IndexBoxInfoModel>)(await _indexboxinforepo.GetAll()).Data).FirstOrDefault(x => x.I_SecId == ism.Section && x.Lang == ism.Lang);

                if (BoxInfo == null)
                {
                    await _indexboxinforepo.Insert(new IndexBoxInfoModel()
                    {
                        I_SecId = ism.Section,
                        I_Title = ism.Title,
                        I_Icon  = ism.Icon,
                        I_Sort  = ism.Sort,
                        Lang    = ism.Lang
                    });

                    await _indexboxinforepo.CommitAllChanges();
                }
                else
                {
                    await _indexboxinforepo.Update(new IndexBoxInfoModel()
                    {
                        I_Id    = BoxInfo.I_Id,
                        I_SecId = ism.Section,
                        I_Title = ism.Title,
                        I_Icon  = ism.Icon,
                        I_Sort  = ism.Sort,
                        Lang    = ism.Lang
                    });

                    await _indexboxinforepo.CommitAllChanges();
                }
                List <IndexBoxProductRelModel> OldRelations = ((List <IndexBoxProductRelModel>)(await _indexsectionrepo.GetAll()).Data).Where(x => x.I_SecId == ism.Section && x.Lang == ism.Lang).ToList();
                foreach (var item in OldRelations)
                {
                    await _indexsectionrepo.Delete(item);
                }
                await _indexsectionrepo.CommitAllChanges();

                foreach (int p in ism.Products)
                {
                    await _indexsectionrepo.Insert(new IndexBoxProductRelModel()
                    {
                        Lang    = ism.Lang,
                        I_Pid   = p,
                        I_SecId = ism.Section
                    });
                }
                await _indexsectionrepo.CommitAllChanges();

                return(new JsonResult(ResponseModel.Success("اطلاعات با موفقیت ذخیره گردید")));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #2
0
        public async Task LogException(Exception ex)
        {
            try
            {
                LogModel log = new LogModel();
                log.L_Title    = ex.Message;
                log.L_Body     = JsonConvert.SerializeObject(ex);
                log.L_FileName = ex.Source;
                await _logRepo.Insert(log);

                await _logRepo.CommitAllChanges();
            }
            catch (Exception e)
            {
                await LogException(e);
            }
        }