Beispiel #1
0
        public IActionResult AssignMessage(int msgid, string st, AssignActivityMessageDto model)
        {
            var actMsg = new ActivityMessage();

            actMsg.Activity.Id       = model.ActivityId;
            actMsg.Message.Id        = msgid;
            actMsg.SendingTime.Id    = "after";
            actMsg.CreatedBy.Id      = partnerManager.GetCurrentUserId(this.HttpContext);
            actMsg.CreatedBy.Account = partnerManager.GetCurrentUserAccount(this.HttpContext);
            actMsg.MessageOrder      = -1;
            var result   = new ActivityMessageRepo(db, partnerManager).Create(actMsg);
            var activity = new ActivityRepo(db, partnerManager).GetActivity(model.ActivityId);

            model.Activity = activity;
            var sendingTime = new CommonCodeRepo(db).GetCodesByType("ActivityMessage.SendingTime");

            model.SendingTime = sendingTime;
            var messages = new MessageTemplateRepo(db, partnerManager).GetAll(activity.Id);
            var listOfSelectedMessage = new List <SelectedMessages>();

            if (messages != null)
            {
                foreach (var item in messages)
                {
                    listOfSelectedMessage.Add(new SelectedMessages
                    {
                        Message     = item,
                        SendingTime = sendingTime
                    });;
                }
            }
            model.Messages         = listOfSelectedMessage;
            model.ActivityMessages = new ActivityMessageRepo(db, partnerManager).GetList(activity.Id, -1);
            return(View(model));
        }
Beispiel #2
0
        public IActionResult Collection(CollectionRptQuery model)
        {
            if (ModelState.IsValid)
            {
                var currentRoleId = partnerManager.GetCurrentUserRole(this.HttpContext);
                var permission    = partnerActivity.GetPartAct("Report.Collection.StatReport", currentRoleId);
                if (permission == null)
                {
                    toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions
                    {
                        Title = ""
                    });
                    return(Redirect(Request.Headers["Referer"].ToString()));
                }
                var result = new CollectionRepo(db).GetStatReport(new CollectionRptQueryParam
                {
                    ChannelId = model.Param.ChannelId,
                    PosId     = model.Param.PosId,
                    StatusId  = model.Param.StatusId,
                    LevelId   = model.Param.LevelId,
                    StartDate = model.Param.StartDate,
                    EndDate   = model.Param.EndDate
                });
                model.Results = result;
            }
            var channels = new CommonCodeRepo(db).GetCodesByType("access.channel");
            var statuses = new CommonCodeRepo(db).GetCodesByType("Collection.Status");

            model.Channels = channels;
            model.Statuses = statuses;
            return(View(model));
        }
        public IActionResult CreateRule()
        {
            var currentRoleId = _PartnerManager.GetCurrentUserRole(this.HttpContext);
            var permission    = _partActRepo.GetPartAct("PartnerActivity.Create", currentRoleId);

            if (permission == null)
            {
                toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions
                {
                    Title = ""
                });
                return(Redirect(Request.Headers["Referer"].ToString()));
            }

            var model            = new CreatePartnerActivity2Dto();
            var detailModel      = new List <CreatePartnerActivityDetailDto>();
            var fromRoles        = new RoleRepo(db, _partActRepo).GetRoles();
            var toRoles          = new RoleRepo(db, _partActRepo).GetRoles();
            var activities       = new ActivityRepo(db, _PartnerManager).GetActivities();
            var maxQueryDuration = new CommonCodeRepo(db).GetCodesByType("queryduration");
            var scopes           = new CommonCodeRepo(db).GetCodesByType("activity.scope");

            model.FromRoles = fromRoles;
            //detailModel.ToRoles = toRoles;
            model.Activities       = activities;
            model.MaxQueryDuration = maxQueryDuration;
            model.Scopes           = scopes;
            model.Details          = detailModel;

            ViewBag.Details = new CreatePartnerActivityDetailDto
            {
                ToRoles = new RoleRepo(db, _partActRepo).GetRoles()
            };
            return(View(model));
        }
        public IActionResult Edit(CreatePartnerActivity2Dto model)
        {
            if (ModelState.IsValid)
            {
                var currentRoleId = _PartnerManager.GetCurrentUserRole(this.HttpContext);
                var permission    = _partActRepo.GetPartAct("PartnerActivity.Edit", currentRoleId);
                if (permission == null)
                {
                    toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions
                    {
                        Title = ""
                    });
                    return(Redirect(Request.Headers["Referer"].ToString()));
                }

                var old = _partActRepo.GetPartAct(model.Id);
                if (old == null)
                {
                    return(View(model));
                }

                var pAct = new PartnerActivity();
                pAct.Id                  = model.Id;
                pAct.Activity.Id         = model.ActivityId;
                pAct.FromRole.Id         = model.FromRoleId ?? 0;
                pAct.MaxQueryRows        = model.MaxQueryRowsNo;
                pAct.MaxQueryDuration.Id = model.MaxQueryDurationId;
                pAct.Scope.Id            = model.ScopeId;
                pAct.OnlyPartnerChildren = model.OnlyPartnerChildren;
                pAct.LastEditOn          = DateTime.Now;
                var result = _partActRepo.Edit(pAct);
                if (result.Success)
                {
                    var audit = new DataAudit();
                    audit.Activity.Id    = "PartnerActivity.Edit";
                    audit.PartnerId      = _PartnerManager.GetCurrentUserId(this.HttpContext);
                    audit.PartnerAccount = _PartnerManager.GetCurrentUserAccount(this.HttpContext);
                    audit.Action.Id      = "Update";
                    audit.Success        = true;
                    audit.OldValue       = old.ToString();
                    audit.NewValue       = pAct.ToString();
                    _auditing.Create(audit);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    model.Error = result.Error;
                }
            }
            var fromRoles        = new RoleRepo(db, _partActRepo).GetRoles();
            var activities       = new ActivityRepo(db, _PartnerManager).GetActivities();
            var maxQueryDuration = new CommonCodeRepo(db).GetCodesByType("queryduration");
            var scopes           = new CommonCodeRepo(db).GetCodesByType("activity.scope");

            model.FromRoles        = fromRoles;
            model.Activities       = activities;
            model.MaxQueryDuration = maxQueryDuration;
            model.Scopes           = scopes;
            return(View(model));
        }
        public IActionResult Create()
        {
            var model            = new CreatePartnerActivityDto();
            var fromRoles        = new RoleRepo(db, _partActRepo).GetRoles();
            var toRoles          = new RoleRepo(db, _partActRepo).GetRoles();
            var activities       = new ActivityRepo(db, _PartnerManager).GetActivities();
            var maxQueryDuration = new CommonCodeRepo(db).GetCodesByType("queryduration");
            var scopes           = new CommonCodeRepo(db).GetCodesByType("activity.scope");

            model.FromRoles        = fromRoles;
            model.ToRoles          = toRoles;
            model.Activities       = activities;
            model.MaxQueryDuration = maxQueryDuration;
            model.Scopes           = scopes;

            return(View(model));
        }
        public IActionResult Create(CreateMoneyTransferDto model)
        {
            if (ModelState.IsValid)
            {
                if (!Utility.ValidYMobileNo(model.PartnerId))
                {
                    model.Error   = "رقم موبايل خاطئ";
                    model.PayType = new CommonCodeRepo(_db).GetCodesByType("pay.type");
                    return(View(model));
                }
                if (model.Amount <= 0)
                {
                    model.Error   = "المبلغ غير صحيح";
                    model.PayType = new CommonCodeRepo(_db).GetCodesByType("pay.type");
                    return(View(model));
                }
                var result = GetBasicInfo(model.PartnerId, model.Amount);
                if (result.Error != "N/A")
                {
                    model.Error   = result.Error;
                    model.PayType = new CommonCodeRepo(_db).GetCodesByType("pay.type");
                    return(View(model));
                }
                result.AmountName    = new MonyToString().NumToStr(result.Amount);
                result.PayTypeName   = new CommonCodeRepo(_db).GetCodesById(model.PayTypeId, "pay.type").Name;
                result.PayTypeId     = model.PayTypeId;
                result.PayNo         = model.PayNo;
                result.PayDate       = model.PayDate;
                result.PayBank       = model.PayBank;
                result.Note          = model.Note;
                result.BillNo        = model.BillNo;
                result.RequestNo     = model.RequestNo;
                result.RequestAmount = model.RequestAmount;
                result.PayType       = new CommonCodeRepo(_db).GetCodesByType("pay.type");
                return(View("Confirmation", result));
            }
            var payTypes = new CommonCodeRepo(_db).GetCodesByType("pay.type");

            model.PayType = payTypes;
            return(View(model));
        }
Beispiel #7
0
        public IActionResult Index()
        {
            var currentRoleId = partnerManager.GetCurrentUserRole(this.HttpContext);
            var permission    = partnerActivity.GetPartAct("BgService.Query", currentRoleId);

            if (permission == null || permission.Details == null || permission.Details.Count == 0)
            {
                toastNotification.AddErrorToastMessage("ليس لديك الصلاحيات الكافية", new ToastrOptions {
                    Title = ""
                });
                return(Redirect(Request.Headers["Referer"].ToString()));
            }
            var model    = new AppBackgroundServiceQueryDto();
            var sources  = new CommonCodeRepo(db).GetCodesByType("bg_service_source");
            var statuses = new CommonCodeRepo(db).GetCodesByType("bg_service_status");

            model.Sources   = sources;
            model.Statuses  = statuses;
            model.StartDate = DateTime.Today.AddMonths(-1);
            model.EndDate   = DateTime.Today;
            return(View(model));
        }
        public IActionResult Edit(int id)
        {
            var currentRoleId = _PartnerManager.GetCurrentUserRole(this.HttpContext);
            var permission    = _partActRepo.GetPartAct("PartnerActivity.Edit", currentRoleId);

            if (permission == null)
            {
                toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions
                {
                    Title = ""
                });
                return(Redirect(Request.Headers["Referer"].ToString()));
            }
            var model  = new CreatePartnerActivity2Dto();
            var result = _partActRepo.GetPartAct(id);

            if (result != null)
            {
                model.Activity            = result.Activity;
                model.ActivityId          = result.Activity.Id;
                model.FromRole            = result.FromRole;
                model.FromRoleId          = result.FromRole.Id;
                model.MaxQueryDurationId  = result.MaxQueryDuration.Id;
                model.MaxQueryRowsNo      = result.MaxQueryRows;
                model.ScopeId             = result.Scope.Id;
                model.OnlyPartnerChildren = result.OnlyPartnerChildren;
            }
            var fromRoles        = new RoleRepo(db, _partActRepo).GetRoles();
            var activities       = new ActivityRepo(db, _PartnerManager).GetActivities();
            var maxQueryDuration = new CommonCodeRepo(db).GetCodesByType("queryduration");
            var scopes           = new CommonCodeRepo(db).GetCodesByType("activity.scope");

            model.FromRoles        = fromRoles;
            model.Activities       = activities;
            model.MaxQueryDuration = maxQueryDuration;
            model.Scopes           = scopes;
            return(View(model));
        }
Beispiel #9
0
        public IActionResult MoneyTransfer()
        {
            var currentRoleId = partnerManager.GetCurrentUserRole(this.HttpContext);
            var permission    = partnerActivity.GetPartAct("Report.MoneyTransfer.StatReport", currentRoleId);

            if (permission == null)
            {
                toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions
                {
                    Title = ""
                });
                return(Redirect(Request.Headers["Referer"].ToString()));
            }
            var channels   = new CommonCodeRepo(db).GetCodesByType("access.channel");
            var transTypes = new CommonCodeRepo(db).GetCodesByType("TransType");
            var model      = new MoneyTransferRptQuery();

            model.Channels        = channels;
            model.TransType       = transTypes;
            model.Param.StartDate = DateTime.Today.Subtract(TimeSpan.FromDays(10));
            model.Param.EndDate   = DateTime.Today.AddDays(1);
            return(View(model));
        }
        public IActionResult Create()
        {
            var currentRoleId = _partnerManager.GetCurrentUserRole(this.HttpContext);
            var permission    = _partnerActivity.GetPartAct("MoneyTransfer.Create", currentRoleId);

            if (permission == null)
            {
                _toastNotification.AddErrorToastMessage("ليس لديك الصلاحيات الكافية", new ToastrOptions {
                    Title = ""
                });
                return(Redirect(Request.Headers["Referer"].ToString()));
            }
            var model = new CreateMoneyTransferDto();
            var currentPartAccount = _partnerManager.GetCurrentUserAccount(this.HttpContext);
            var currentPart        = _partnerManager.GetPartnerByAccount(currentPartAccount);

            model.CreatorBalance = currentPart.Balance - currentPart.Reserved;
            var payTypes = new CommonCodeRepo(_db).GetCodesByType("pay.type");

            model.PayType = payTypes;
            model.PayDate = DateTime.Today;
            return(View(model));
        }
Beispiel #11
0
        public IActionResult Create()
        {
            var currentRoleId = partnerManager.GetCurrentUserRole(this.HttpContext);
            var permission    = partnerActivity.GetPartAct("BgService.Create", currentRoleId);

            if (permission == null)
            {
                toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions
                {
                    Title = ""
                });
                return(Redirect(Request.Headers["Referer"].ToString()));
            }

            var model = new CreateBackgroundServiceDto();

            model.StartDate = DateTime.Now.AddDays(-30);
            model.EndDate   = DateTime.Now;
            var sources = new CommonCodeRepo(db).GetCodesByType("bg_service_source");

            model.Sources = sources;
            return(View(model));
        }
Beispiel #12
0
        public async Task <IActionResult> Index(AppBackgroundServiceQueryDto model)
        {
            var currentRoleId  = partnerManager.GetCurrentUserRole(this.HttpContext);
            var currentId      = partnerManager.GetCurrentUserId(this.HttpContext);
            var currentAccount = partnerManager.GetCurrentUserAccount(this.HttpContext);
            var permission     = partnerActivity.GetPartAct("BgService.Query", currentRoleId);

            if (permission == null || permission.Details == null || permission.Details.Count == 0)
            {
                toastNotification.AddErrorToastMessage("ليس لديك الصلاحيات الكافية", new ToastrOptions {
                    Title = ""
                });
                return(Redirect(Request.Headers["Referer"].ToString()));
            }


            var results = await new AppBackgroundServiceRepo(db).GetBackgroundServicesAsync(new AppBackgroundServiceRepo.BackgroundServiceListParam
            {
                Id           = model.Id,
                PartnerId    = model.PartnerId,
                CreatedById  = model.CreatedById,
                IncludeDates = model.IncludeDates,
                StartDate    = model.StartDate,
                EndDate      = model.EndDate,
                Source       = model.Source,
                Status       = model.Status,
                Name         = model.Name
            }, permission, currentId, currentAccount);

            model.Results = results;
            var sources  = new CommonCodeRepo(db).GetCodesByType("bg_service_source");
            var statuses = new CommonCodeRepo(db).GetCodesByType("bg_service_status");

            model.Sources  = sources;
            model.Statuses = statuses;
            return(View(model));
        }
Beispiel #13
0
        public IActionResult AssignMessage(string id)
        {
            var activity = new ActivityRepo(db, partnerManager).GetActivity(id);

            if (activity == null)
            {
                toastNotification.AddErrorToastMessage("البيانات غير موجودة ", new ToastrOptions {
                    Title = ""
                });
                return(Redirect(Request.Headers["Referer"].ToString()));
            }
            var model = new AssignActivityMessageDto();

            model.ActivityId = activity.Id;
            model.Activity   = activity;
            var sendingTime = new CommonCodeRepo(db).GetCodesByType("ActivityMessage.SendingTime");

            model.SendingTime = sendingTime;
            var messages = new MessageTemplateRepo(db, partnerManager).GetAll(activity.Id);
            var listOfSelectedMessage = new List <SelectedMessages>();

            if (messages != null)
            {
                foreach (var item in messages)
                {
                    listOfSelectedMessage.Add(new SelectedMessages
                    {
                        Message     = item,
                        SendingTime = sendingTime
                    });;
                }
            }
            model.Messages         = listOfSelectedMessage;
            model.ActivityMessages = new ActivityMessageRepo(db, partnerManager).GetList(id, -1);
            return(View(model));
        }
Beispiel #14
0
        public IActionResult CollectionToExcel(CollectionRptQuery model)
        {
            if (ModelState.IsValid)
            {
                var currentRoleId = partnerManager.GetCurrentUserRole(this.HttpContext);
                var permission    = partnerActivity.GetPartAct("Report.Collection.StatReport.ExportToExcel", currentRoleId);
                if (permission == null)
                {
                    toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions
                    {
                        Title = ""
                    });
                    return(Redirect(Request.Headers["Referer"].ToString()));
                }
                var param = new CollectionRptQueryParam
                {
                    ChannelId = model.Param.ChannelId,
                    PosId     = model.Param.PosId,
                    StatusId  = model.Param.StatusId,
                    LevelId   = model.Param.LevelId,
                    StartDate = model.Param.StartDate,
                    EndDate   = model.Param.EndDate
                };
                var result = new CollectionRepo(db).GetStatReport(param);
                model.Results = result;
                if (result != null)
                {
                    using (var workbook = new XLWorkbook())
                    {
                        var worksheet = workbook.AddWorksheet("Collections");
                        worksheet.SetRightToLeft();
                        worksheet.ColumnWidth = 15;
                        var currRow = 1;
                        worksheet.Range(1, 1, 1, 7).Merge().Value = param.Title;
                        worksheet.Range(1, 1, 1, 7).Style.Fill.BackgroundColor = XLColor.LightYellow;
                        worksheet.Cell(currRow, 1).Style.Alignment.SetVertical(XLAlignmentVerticalValues.Center);
                        worksheet.Cell(currRow, 1).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                        worksheet.Row(1).Height              = 100;
                        worksheet.Row(1).Style.Font.Bold     = true;
                        worksheet.Row(1).Style.Font.FontSize = 16;
                        ++currRow;
                        worksheet.Cell(currRow, 1).Value           = "القناة";
                        worksheet.Cell(currRow, 2).Value           = model.Param.LevelId == "pos" ? "رقم النقطة" : "اليوم";
                        worksheet.Cell(currRow, 3).Value           = model.Param.LevelId == "pos" ? "رقم النقطة" : "";
                        worksheet.Cell(currRow, 4).Value           = "الحالة";
                        worksheet.Cell(currRow, 5).Value           = "عدد العمليات";
                        worksheet.Cell(currRow, 6).Value           = "اجمالي المبلغ";
                        worksheet.Cell(currRow, 7).Value           = "عدد النقاط";
                        worksheet.Row(currRow).Style.Font.Bold     = true;
                        worksheet.Row(currRow).Style.Font.FontSize = 14;
                        worksheet.Row(currRow).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                        worksheet.Row(currRow).Style.Alignment.SetVertical(XLAlignmentVerticalValues.Center);
                        worksheet.Row(currRow).Height = 25;
                        worksheet.Range(currRow, 1, currRow, 7).Style.Fill.BackgroundColor = XLColor.LightPastelPurple;

                        foreach (var item in result)
                        {
                            ++currRow;
                            worksheet.Columns(6, 6).Style.NumberFormat.SetFormat("#,##0.00");
                            worksheet.Columns(5, 5).Style.NumberFormat.SetFormat("#,##0");
                            worksheet.Columns(7, 7).Style.NumberFormat.SetFormat("#,##0");
                            worksheet.Row(currRow).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                            worksheet.Row(currRow).Style.Alignment.SetVertical(XLAlignmentVerticalValues.Center);
                            worksheet.Cell(currRow, 1).Value = item.Channel;
                            worksheet.Cell(currRow, 2).Value = model.Param.LevelId == "pos" ? item.Partner.Id : item.CollDay;
                            worksheet.Cell(currRow, 3).Value = model.Param.LevelId == "pos" ? item.Partner.Name : "";
                            worksheet.Cell(currRow, 4).Value = item.Status.Name;
                            worksheet.Cell(currRow, 5).Value = item.Count;
                            worksheet.Cell(currRow, 6).Value = item.Amount;
                            worksheet.Cell(currRow, 7).Value = item.DistinctCount;
                            worksheet.Row(currRow).Height    = 20;
                        }
                        ++currRow;
                        worksheet.Row(currRow).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                        worksheet.Row(currRow).Style.Alignment.SetVertical(XLAlignmentVerticalValues.Center);
                        worksheet.Row(currRow).Height              = 25;
                        worksheet.Row(currRow).Style.Font.Bold     = true;
                        worksheet.Row(currRow).Style.Font.FontSize = 12;
                        worksheet.Cell(currRow, "E").SetFormulaA1("=SUM(E3:E" + (currRow - 1) + ")");
                        worksheet.Cell(currRow, "F").SetFormulaA1("=SUM(F3:F" + (currRow - 1) + ")");
                        worksheet.Cell(currRow, "G").SetFormulaA1("=SUM(G3:G" + (currRow - 1) + ")");
                        worksheet.Range(currRow, 1, currRow, 4).Merge().Value = "الاجــمـــالــي";
                        worksheet.Range(currRow, 1, currRow, 7).Style.Fill.BackgroundColor = XLColor.LightPastelPurple;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.BottomBorder        = XLBorderStyleValues.Thick;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.BottomBorderColor   = XLColor.Black;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.LeftBorder          = XLBorderStyleValues.Thick;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.LeftBorderColor     = XLColor.Black;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.RightBorder         = XLBorderStyleValues.Thick;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.RightBorderColor    = XLColor.Black;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.TopBorder           = XLBorderStyleValues.Thick;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.TopBorderColor      = XLColor.Black;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.InsideBorder        = XLBorderStyleValues.Thin;
                        worksheet.Range(1, 1, currRow, 7).Style.Border.InsideBorderColor   = XLColor.LightGray;
                        using (var stream = new MemoryStream())
                        {
                            workbook.SaveAs(stream);
                            var content = stream.ToArray();
                            return(File(
                                       content,
                                       "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                                       "Collection" + DateTime.Today.ToString("yyyyMMdd") + ".xlsx"
                                       ));
                        }
                    }
                }
            }
            var channels = new CommonCodeRepo(db).GetCodesByType("access.channel");
            var statuses = new CommonCodeRepo(db).GetCodesByType("Collection.Status");

            model.Channels = channels;
            model.Statuses = statuses;
            return(View("Collection", model));
        }
        public IActionResult CreateRule(CreatePartnerActivity2Dto model)
        {
            if (ModelState.IsValid)
            {
                var currentRoleId = _PartnerManager.GetCurrentUserRole(this.HttpContext);
                var permission    = _partActRepo.GetPartAct("PartnerActivity.Create", currentRoleId);
                if (permission == null)
                {
                    toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions
                    {
                        Title = ""
                    });
                    return(Redirect(Request.Headers["Referer"].ToString()));
                }

                var pAct = new PartnerActivity();
                pAct.Activity.Id         = model.ActivityId;
                pAct.FromRole.Id         = model.FromRoleId ?? 0;
                pAct.MaxQueryRows        = model.MaxQueryRowsNo;
                pAct.MaxQueryDuration.Id = model.MaxQueryDurationId;
                pAct.Scope.Id            = model.ScopeId;
                pAct.OnlyPartnerChildren = model.OnlyPartnerChildren;
                pAct.CreatedBy.Id        = _PartnerManager.GetCurrentUserId(this.HttpContext);
                pAct.CreatedBy.Account   = _PartnerManager.GetCurrentUserAccount(this.HttpContext);

                var result = _partActRepo.Create(pAct);
                if (result.Success)
                {
                    var listModel = new ListPartnerActivityDto();
                    listModel.Activities = new SelectList(new ActivityRepo(db, _PartnerManager).GetActivities(), "Id", "Name");
                    listModel.FromRoles  = new SelectList(new RoleRepo(db, _partActRepo).GetRoles(), "Id", "Name");
                    //return View("Index", listModel);
                    return(RedirectToAction("Detail", "PartActivity", new { id = result.AffectedCount }));
                }
                else if (result.AffectedCount == -504)
                {
                    var permission2 = _partActRepo.GetPartAct("PartnerActivity.Query", currentRoleId);
                    if (permission2 == null)
                    {
                        toastNotification.AddErrorToastMessage("تم انشاء هذه الصلاحية مسبقا ", new ToastrOptions {
                            Title = ""
                        });
                    }
                    else
                    {
                        return(RedirectToAction("Detail", "PartActivity", new { id = permission2.Id }));
                    }
                }
                else
                {
                    toastNotification.AddErrorToastMessage("لم يتم انشاء الصلاحية ، يرجى المحاولة لاحقا ", new ToastrOptions {
                        Title = ""
                    });
                }
            }

            var fromRoles        = new RoleRepo(db, _partActRepo).GetRoles();
            var activities       = new ActivityRepo(db, _PartnerManager).GetActivities();
            var maxQueryDuration = new CommonCodeRepo(db).GetCodesByType("queryduration");
            var scopes           = new CommonCodeRepo(db).GetCodesByType("activity.scope");

            model.FromRoles        = fromRoles;
            model.Activities       = activities;
            model.MaxQueryDuration = maxQueryDuration;
            model.Scopes           = scopes;
            return(View(model));
        }
Beispiel #16
0
        public IActionResult Create(CreateBackgroundServiceDto model)
        {
            if (model.Id > 0)
            {
                toastNotification.AddErrorToastMessage("لم يتم حفظ الطلب ، لقد تم حفظه مسبقا", new ToastrOptions
                {
                    Title = ""
                });
            }
            else if (ModelState.IsValid)
            {
                var currentRoleId = partnerManager.GetCurrentUserRole(this.HttpContext);
                var currentId     = partnerManager.GetCurrentUserId(this.HttpContext);
                var permission    = partnerActivity.GetPartAct("BgService.Create", currentRoleId);
                if (permission == null)
                {
                    toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions {
                        Title = ""
                    });
                    //return Redirect(Request.Headers["Referer"].ToString());
                }
                else if (permission.Details == null || permission.Details.Count == 0)
                {
                    toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions {
                        Title = ""
                    });
                    //return Redirect(Request.Headers["Referer"].ToString());
                }
                else if (model.StartDate != null && model.EndDate != null && model.StartDate > model.EndDate)
                {
                    ModelState.AddModelError("EndDate", "تاريخ النهاية اقل من تاريخ البداية");
                }
                else if (string.IsNullOrEmpty(model.PartnerId) || model.PartnerAccount <= 0)
                {
                    toastNotification.AddErrorToastMessage("يجب تحديد الجهة المطلوب بياناتها", new ToastrOptions {
                        Title = ""
                    });
                    //return Redirect(Request.Headers["Referer"].ToString());
                }
                else
                {
                    var targetPartner = partnerManager.GetPartnerByAccount(model.PartnerAccount);
                    if (targetPartner == null)
                    {
                        toastNotification.AddErrorToastMessage("الجهة المراد بياناتها غير موجودة", new ToastrOptions {
                            Title = ""
                        });
                        return(Redirect(Request.Headers["Referer"].ToString()));
                    }
                    if (!permission.Details.Exists(m => m.ToRole.Id == targetPartner.Role.Id))
                    {
                        toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية لطلب بيانات لهذه الجهة", new ToastrOptions {
                            Title = ""
                        });
                        return(Redirect(Request.Headers["Referer"].ToString()));
                    }

                    if (permission.Scope.Id == "CurOpOnly" && targetPartner.Id != currentId)
                    {
                        toastNotification.AddErrorToastMessage("صلاحيتك محدودة لطلب بيانات لرقمك فقط", new ToastrOptions {
                            Title = ""
                        });
                        return(Redirect(Request.Headers["Referer"].ToString()));
                    }

                    if (permission.Scope.Id == "Exclusive" && targetPartner.RefPartner.Id != currentId)
                    {
                        toastNotification.AddErrorToastMessage("صلاحيتك محدودة لطلب بيانات للجهات التابعة لك فقط", new ToastrOptions {
                            Title = ""
                        });
                        return(Redirect(Request.Headers["Referer"].ToString()));
                    }

                    var createdObj = new AppBackgroundService();
                    createdObj.CreatedBy.Id      = partnerManager.GetCurrentUserId(this.HttpContext);
                    createdObj.CreatedBy.Account = partnerManager.GetCurrentUserAccount(this.HttpContext);
                    createdObj.Source.Id         = model.Source;
                    createdObj.Name                  = model.Name;
                    createdObj.Partner.Id            = model.PartnerId;
                    createdObj.Partner.Account       = model.PartnerAccount;
                    createdObj.StartDate             = model.StartDate ?? DateTime.MinValue;
                    createdObj.EndDate               = model.EndDate ?? DateTime.MinValue;
                    createdObj.Note                  = model.Note;
                    createdObj.ActionPartner.Id      = model.ActionPartnerId;
                    createdObj.ActionPartner.Account = model.ActionPartnerAccount;
                    createdObj.ActiveTime            = model.ActiveTime ?? DateTime.MinValue;
                    var result = new AppBackgroundServiceRepo(db).Create(createdObj);
                    if (result.Success)
                    {
                        ModelState.Clear();
                        model.Id = result.AffectedCount;
                        toastNotification.AddSuccessToastMessage("تم حفظ العملية بنجاح، لمعرفة حالتها يرجى الاستعلام من شاشة استعلام الطلبات", new ToastrOptions
                        {
                            Title = ""
                        });
                    }
                    else
                    {
                        toastNotification.AddErrorToastMessage("لم يتم حفظ الطلب " + result.AffectedCount, new ToastrOptions
                        {
                            Title = ""
                        });
                    }
                }
            }
            var sources = new CommonCodeRepo(db).GetCodesByType("bg_service_source");

            model.Sources = sources;
            return(View(model));
        }