Ejemplo n.º 1
0
        public async Task <IActionResult> GetDedicatedLabels(CdTypeErth cdTypeErth, int from = 0, int count = 10, bool countOnly = false)
        {
            try
            {
                var labels = dbContext.CdLabels.Include(l => l.RegisteredLabels)
                             .Where(l =>
                                    l.TypeErth == (int)cdTypeErth &&
                                    (
                                        string.IsNullOrEmpty(l.CustomerName) == false ||
                                        string.IsNullOrEmpty(l.CustomerUnited) == false ||
                                        l.RegisteredLabels.Count > 0
                                    )
                                    )
                             .OrderBy(l => l.RegisteredLabels.Count);

                if (countOnly)
                {
                    var n = await labels.CountAsync();

                    return(Ok(new TbActionResult <int> {
                        Success = true,
                        Object = n,
                        Desc = $"تعداد کل سی‌دی‌های اختصاص یافته: {n}"
                    }));
                }

                var result = await labels.Skip(from).Take(count).Select(
                    l => new DedicatedLablsVM {
                    FullName        = l.CustomerName,
                    Id              = l.Id,
                    Label           = l.Label,
                    RegisteredCount = l.RegisteredLabels.Count,
                    United          = l.CustomerUnited
                }
                    ).ToListAsync();

                return(Ok(new TbActionResult <List <DedicatedLablsVM> > {
                    Success = true,
                    Object = result,
                    Desc = "با موفقیت بازیابی شد"
                }));
            }
            catch (System.Exception err)
            {
                return(BadRequest(new TbActionResult <DedicatedLablsVM>
                {
                    Success = false,
                    Object = null,
                    Desc = $"خطا در انجام عملیات.. {err.Message}"
                }));
            }
        }
Ejemplo n.º 2
0
        public static string CreateActiveCode(string strSn, CdTypeErth cdTypeErth)
        {
            const ulong BaseCodeForProEdition     = 5245689851422347;
            const ulong BaseCodeForStudentEdition = 3335647891306510;

            char[] space = new char[1] {
                ' '
            };

            ulong sn = 0;

            try
            {
                string str   = strSn.Trim(space);
                byte[] bytes = new byte[str.Length];



                Encoding.ASCII.GetBytes(str, 0, str.Length, bytes, 0);


                for (int i = 0; i < bytes.Length; i++)
                {
                    sn = sn * 255 + bytes[i];
                }

                switch (cdTypeErth)
                {
                case CdTypeErth.Pro:
                    sn = sn - BaseCodeForProEdition;
                    break;

                case CdTypeErth.Student:
                    sn = sn - BaseCodeForStudentEdition;
                    break;
                }
            }
            catch
            {
                return("خطا در ایجاد کد فعالسازی. لطفا با ۰۹۱۳۲۷۰۸۳۴۱ تماس بگیرید.");
            }

            return(sn.ToString());
        }