Exemple #1
0
        public async Task <ResponseStructure> Insert(ProductCombineModel entity)
        {
            try
            {
                var all = ((List <ProductCombineModel>)(await this.GetAll()).Data);
                if (all.Count(x => x.X_ProductId == entity.X_ProductId && x.X_WarrantyId == entity.X_WarrantyId && x.X_ColorId == entity.X_ColorId && !x.X_IsDeleted) > 0)
                {
                    return(ResponseModel.Error("ترکیب آماری مورد نظر برای گارانتی و رنگ انتخابی قبلا تعریف شده است"));
                }
                if (entity.X_Default)
                {
                    var allCombines = all.Where(x => x.X_ProductId == entity.X_ProductId).ToList();
                    foreach (var cmb in allCombines)
                    {
                        cmb.X_Default = false;
                    }
                    _context.ProductCombine.UpdateRange(allCombines);
                    await this.CommitAllChanges();
                }

                await this.DbSet.AddAsync(entity : entity);

                await this.CommitAllChanges();

                return(ResponseModel.Success("ترکیب آماری با موفقیت ایجاد گردید"));
            }
            catch (Exception ex)
            {
                return(ResponseModel.ServerInternalError(data: ex));
            }
        }
        public async Task <ResponseStructure> UpdateRelation(List <GiftProductModel> data, int prodid)
        {
            try
            {
                if (data.Count() > 1)
                {
                    return(ResponseModel.Error("به هر محصول فقط میتوان یک هدیه نسبت داد"));
                }

                var rel = this._context.GiftProduct.ToList();
                this._context.GiftProduct.RemoveRange(rel.Where(x => x.X_MainProdId == prodid).ToList());
                await this.CommitAllChanges();

                if (data == null || data.Count() == 1)
                {
                    await this._context.GiftProduct.AddRangeAsync(data);

                    await this.CommitAllChanges();
                }

                return(ResponseModel.Success("عملیات با موفقیت انجام گردید"));
            }
            catch (Exception ex)
            {
                return(ResponseModel.ServerInternalError(data: ex));
            }
        }
        public IActionResult UpdateLogic(FieldList entity)
        {
            if (entity.Id == 0)
            {
                return(View("Update", ResponseModel.Error("MetaField Id 不能为空", entity)));
            }
            if (string.IsNullOrEmpty(entity.Name))
            {
                return(View("Update", ResponseModel.Error("MetaField Name 不能为空", entity)));
            }
            if (string.IsNullOrEmpty(entity.Code))
            {
                return(View("Update", ResponseModel.Error("MetaField Code 不能为空", entity)));
            }
            //校验code格式
            if (!entity.Code.IsAlnum(2, 50))
            {
                return(View("Update", ResponseModel.Error("编码不合法,2-50位且只能包含字母和数字(字母开头)", entity)));
            }

            //检查编码或名称重复
            var checkResult = fieldListService.CheckSameCodeOrName(CurrentMetaObjectId, entity);

            if (!checkResult.IsSuccess)
            {
                return(View("Update", checkResult.ToResponseModel()));
            }

            //更新操作
            fieldListService.Update(entity);

            return(RedirectToAction("List"));
        }
Exemple #4
0
        public async Task <ResponseStructure> RechargeWallet(int user, decimal amount, string recieptInfo = "")
        {
            try
            {
                UserModel userModel = this._context.Users.FirstOrDefault(x => x.U_Id == user);
                if (amount == 0)
                {
                    return(ResponseModel.Error("Cannot increase zero amount"));
                }
                userModel.U_Wallet = userModel.U_Wallet + amount;
                this._context.Users.Update(userModel);
                await this._context.SaveChangesAsync();

                await this.LogTransaction(new WalletHistoryModel()
                {
                    WH_AdderId         = 0,
                    WH_CustomerId      = user,
                    WH_Amount          = amount,
                    WH_TransactionType = 1,
                    WH_PayType         = 0,
                    WH_PayBankRecip    = recieptInfo
                });

                return(ResponseModel.Success("Transaction completed successfully."));
            }
            catch (Exception ex)
            {
                return(ResponseModel.ServerInternalError("Server Internal Error", ex));
            }
        }
        public IActionResult UpdateLogic(TriggerScript triggerScript)
        {
            try
            {
                if (triggerScript.Id == 0)
                {
                    return(View("Update", ResponseModel.Error("Id 不能为空", triggerScript)));
                }
                if (string.IsNullOrEmpty(triggerScript.Name))
                {
                    return(View("Update", ResponseModel.Error("Name 不能为空", triggerScript)));
                }
                if (string.IsNullOrEmpty(triggerScript.Code))
                {
                    return(View("Update", ResponseModel.Error("Code 不能为空", triggerScript)));
                }

                //check script
                var checkResult2 = triggerScriptService.CompilateAndCheckScript(triggerScript.Script, CurrentApplicationCode);
                if (!checkResult2.IsSuccess)
                {
                    return(View("Update", ResponseModel.Error($"脚本存在错误:\r\n{checkResult2.Message}", triggerScript)));
                }

                triggerScript.ModifyBy = CurrentUserId;
                //更新操作
                triggerScriptService.Update(triggerScript);

                return(RedirectToAction("List"));
            }
            catch (Exception ex)
            {
                return(View("Update", ResponseModel.Error(ex.ToString(), triggerScript)));
            }
        }
Exemple #6
0
 public async Task <ResponseStructure> AdminLogin(UserModel um)
 {
     try
     {
         var  getAll  = (List <UserModel>)(await GetAll()).Data;
         var  exists  = getAll.FirstOrDefault(x => x.U_Email == um.U_Email);
         bool truepwd = false;
         if (exists == null || !CryptoJsService.verifyPassword(exists.U_Password, um.U_Password))
         {
             return(ResponseModel.Error("Sorry,we couldn't find an account with that username and password."));
         }
         if (exists.U_Status == 2)
         {
             return(ResponseModel.Error("Your account has been suspened."));
         }
         if (um.U_Role == 1)
         {
             var perms = _context.Permissions.Where(x => x.Perm_Uid == exists.U_Id).ToList();
             foreach (var perm in perms)
             {
                 um.Permissions.Add(perm.Perm_Urlid);
             }
         }
         var token = TokenService.GenerateToken(exists.U_Id, exists.U_Name + " " + exists.U_Family, exists.U_Email);
         um.Token = token;
         return(ResponseModel.Success(data: um));
     }
     catch (Exception ex)
     {
         return(ResponseModel.ServerInternalError(data: ex));
     }
 }
Exemple #7
0
        public async Task <ResponseStructure> GetAll()
        {
            try
            {
                List <ProductCategoryModel> data = this._context.ProductCategory.Where(x => x.PC_IsDeleted == false).ToList();
                foreach (var item in data)
                {
                    string ParentTitle = "****";
                    int    lvl         = 1;
                    if (item.PC_ParentId != 0)
                    {
                        var parent = await this.GetById(item.PC_ParentId);

                        ParentTitle = parent.PC_Title;
                        lvl         = await this.GetCategoryLevel(item.PC_Id);
                    }
                    data.FirstOrDefault(x => x.PC_Id == item.PC_Id).PC_ParentTitle = ParentTitle;
                    data.FirstOrDefault(x => x.PC_Id == item.PC_Id).PC_Level       = lvl;
                    if (lvl == Constants.MAX_CAT_LEVEL || lvl == (Constants.MAX_CAT_LEVEL - 1))
                    {
                        data.FirstOrDefault(x => x.PC_Id == item.PC_Id).PC_AttrAble = true;
                    }
                }
                data = data.OrderBy(x => x.PC_Level).ToList();

                return(ResponseModel.Success(data: data));
            }
            catch (Exception ex)
            {
                return(ResponseModel.Error(msg: ex.Message, data: ex));
            }
        }
Exemple #8
0
        public IActionResult UpdateLogic(FieldList entity)
        {
            if (entity.Id == 0)
            {
                return(View("Update", ResponseModel.Error("MetaField Id 不能为空", entity)));
            }
            if (string.IsNullOrEmpty(entity.Name))
            {
                return(View("Update", ResponseModel.Error("MetaField Name 不能为空", entity)));
            }
            if (string.IsNullOrEmpty(entity.Code))
            {
                return(View("Update", ResponseModel.Error("MetaField Code 不能为空", entity)));
            }

            //检查编码或名称重复
            var checkResult = fieldListService.CheckSameCodeOrName(CurrentMetaObjectId, entity);

            if (!checkResult.IsSuccess)
            {
                return(View("Update", checkResult.ToResponseModel()));
            }

            entity.ModifyBy = CurrentUserId;
            //更新操作
            fieldListService.Update(entity);

            return(RedirectToAction("List"));
        }
Exemple #9
0
 public async Task <ResponseStructure> uploadDocument(IFormFile file, string fireFlag, string loc)
 {
     try
     {
         string[] allowtype = new string[] { "application/msword", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "text/plain", "application/pdf" };
         string   ftype     = file.ContentType;
         if ((allowtype.Contains(ftype)))
         {
             string uploadPath = FileLocMapper.LocateMediaFile(fireFlag, loc);
             //long fsize = file[i].Length;
             string fname    = DateTime.UtcNow.Millisecond + UtilesService.GenerateNewRandom() + "." + System.IO.Path.GetExtension(file.FileName).Substring(1);
             var    filePath = Path.Combine(uploadPath, fname);
             using (var stream = new FileStream(filePath, FileMode.Create))
             {
                 await file.CopyToAsync(stream);
             }
             return(ResponseModel.Success(msg: "فایل با موفقیت آپلود گردید", data: fname));
         }
         else
         {
             return(ResponseModel.Error("نوع فایل ارسال شده صحیح نمیباشد"));
         }
     }
     catch (Exception e)
     {
         return(ResponseModel.Error("خطای ناشناخته در سیستم رخ داده است" + e.Message));
     }
     return(null);
 }
        public IActionResult AddLogic(SevenTiny.Cloud.MultiTenantPlatform.Core.Entity.Application application)
        {
            if (string.IsNullOrEmpty(application.Name))
            {
                return(View("Add", ResponseModel.Error("Application Name Can Not Be Null!", application)));
            }
            if (string.IsNullOrEmpty(application.Code))
            {
                return(View("Add", ResponseModel.Error("Application Code Can Not Be Null!", application)));
            }
            //校验code格式
            if (!application.Code.IsAlnum(2, 50))
            {
                return(View("Add", ResponseModel.Error("编码不合法,2-50位且只能包含字母和数字(字母开头)", application)));
            }

            application.CreateBy = CurrentUserId;
            var addResult = applicationService.Add(application);

            if (!addResult.IsSuccess)
            {
                return(View("Add", addResult.ToResponseModel()));
            }

            return(RedirectToAction("List"));
        }
Exemple #11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().ConfigureApiBehaviorOptions(options =>
            {
                options.InvalidModelStateResponseFactory = c =>
                {
                    var errors = string.Join('\n', c.ModelState.Values.Where(i => i.Errors.Count > 0)
                                             .SelectMany(i => i.Errors)
                                             .Select(i => i.ErrorMessage));
                    return(new OkObjectResult(ResponseModel.Error(errors))); // custom validasyon modifiye
                };
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddFluentValidation(x => x.RegisterValidatorsFromAssemblyContaining <OrderInfoModelValidation>())
            .Services.AddTransient <IValidatorInterceptor, ValidationHandler>();

            var connection = Configuration.GetSection("ConnectionString").Value;

            services
            .AddDatabase <SqliteConnection>(x => { x.ConnectionString = connection; x.CreateOrderDatabase(); })
            .AddOrdersLogic()
            .AddMediatR(typeof(LogicConfigurationExtension).Assembly)
            .AddSwaggerGen(x =>
            {
                x.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Order Api", Version = "v1"
                });
            });
        }
        public IActionResult UpdateLogic(MetaObject metaObject)
        {
            if (metaObject.Id == 0)
            {
                return(View("Update", ResponseModel.Error("MetaObject Id Can Not Be Null!", metaObject)));
            }
            if (string.IsNullOrEmpty(metaObject.Name))
            {
                return(View("Update", ResponseModel.Error("MetaObject Name Can Not Be Null!", metaObject)));
            }
            if (string.IsNullOrEmpty(metaObject.Code))
            {
                return(View("Update", ResponseModel.Error("MetaObject Code Can Not Be Null!", metaObject)));
            }
            //校验code格式,编辑时界面会将'.'传递到后台,不能用下面正则校验,且编辑操作并不会更新编码,无需在此校验
            //if (!metaObject.Code.IsAlnum(2, 50))
            //{
            //    return View("Update", ResponseModel.Error("编码不合法,2-50位且只能包含字母和数字(字母开头)", metaObject));
            //}

            metaObject.ModifyBy = CurrentUserId;
            if (metaObjectService.ExistSameNameWithOtherIdByApplicationId(CurrentApplicationId, metaObject.Id, metaObject.Name))
            {
                return(View("Update", ResponseModel.Error("MetaObject Name Has Been Exist!", metaObject)));
            }

            metaObjectService.Update(metaObject);
            return(RedirectToAction("List"));
        }
        public IActionResult AddLogic(MetaObject metaObject)
        {
            if (string.IsNullOrEmpty(metaObject.Name))
            {
                return(View("Add", ResponseModel.Error("MetaObject Name Can Not Be Null!", metaObject)));
            }
            if (string.IsNullOrEmpty(metaObject.Code))
            {
                return(View("Add", ResponseModel.Error("MetaObject Code Can Not Be Null!", metaObject)));
            }
            //校验code格式
            if (!metaObject.Code.IsAlnum(2, 50))
            {
                return(View("Add", ResponseModel.Error("编码不合法,2-50位且只能包含字母和数字(字母开头)", metaObject)));
            }

            metaObject.CreateBy = CurrentUserId;
            var addResult = metaObjectService.AddMetaObject(CurrentApplicationId, CurrentApplicationCode, metaObject);

            if (!addResult.IsSuccess)
            {
                return(View("Add", addResult.ToResponseModel()));
            }

            return(RedirectToAction("List"));
        }
Exemple #14
0
        public async Task <ResponseStructure> Update(ProductCombineModel entity)
        {
            try
            {
                var all = ((List <ProductCombineModel>)(await this.GetAll()).Data);
                if (all.Count(x => x.X_Id != entity.X_Id && x.X_ProductId == entity.X_ProductId && x.X_WarrantyId == entity.X_WarrantyId && x.X_ColorId == entity.X_ColorId && !x.X_IsDeleted) > 0)
                {
                    return(ResponseModel.Error("ترکیب آماری مورد نظر برای گارانتی و رنگ انتخابی قبلا تعریف شده است"));
                }
                if (entity.X_Default)
                {
                    var allCombines = all.Where(x => x.X_ProductId == entity.X_ProductId).ToList();
                    foreach (var cmb in allCombines)
                    {
                        cmb.X_Default = false;
                    }
                    _context.ProductCombine.UpdateRange(allCombines);
                    await this.CommitAllChanges();
                }
                var item = await this.GetById(entity.X_Id);

                entity.Created_At = item.Created_At;
                entity.Updated_At = DateTime.Now;
                this._context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
                this._context.ProductCombine.Update(entity);
                await this._context.SaveChangesAsync();

                return(ResponseModel.Success("رکورد مورد نظر با موفقیت بروزرسانی گردید"));
            }
            catch (Exception ex)
            {
                return(ResponseModel.ServerInternalError(data: ex));
            }
        }
Exemple #15
0
        public async Task <ResponseStructure> UpdateProfile(HttpRequest httpRequest, int userId)
        {
            try
            {
                UserModel userModel = await this.GetById(userId);

                if (userModel == null)
                {
                    return(ResponseModel.Error("Your login token has expired.", new { EXPIREDTOKEN = true }));
                }
                var           data = httpRequest.Headers["UpdateData"];
                var           dec  = Barayand.Common.Services.CryptoJsService.DecryptStringAES(data);
                RegisterModel rm   = JsonConvert.DeserializeObject <RegisterModel>(dec);
                userModel.U_Avatar        = rm.Avatar;
                userModel.U_Family        = rm.Family;
                userModel.U_Name          = rm.Name;
                userModel.U_Phone         = rm.Phone;
                userModel.U_HomeTel       = rm.HomeTel;
                userModel.U_IdentityCode  = rm.IdentityCode;
                userModel.U_CreditCardNum = rm.CreditCardNum;
                userModel.U_BirthDate     = rm.BirthDate;
                userModel.U_Email         = rm.Email;
                return(await this.Update(userModel));
            }
            catch (Exception ex)
            {
                return(ResponseModel.ServerInternalError(data: ex));
            }
        }
Exemple #16
0
        public async Task <ResponseStructure> UploadBase64(string data, string loc, string fireFlag, int w = 500, int h = 500)
        {
            try
            {
                string       root       = FileLocMapper.LocateMediaFile(fireFlag, loc);
                var          split      = data.Split(',');
                var          strings    = split[1].Split('-');
                byte[]       imageBytes = Convert.FromBase64String(strings[0]);
                MemoryStream ms         = new MemoryStream(imageBytes, 0, imageBytes.Length);
                ms.Write(imageBytes, 0, imageBytes.Length);
                Image  image    = Image.FromStream(ms, true);
                string fileName = DateTime.UtcNow.Millisecond + UtilesService.RandomDigit(15) + UtilesService.getFileExtByContentType(split[0]);
                using (MemoryStream mOutput = new MemoryStream())
                {
                    image.Save(mOutput, image.RawFormat);
                    using (FileStream fs = File.Create(String.Concat(root, fileName).ToLowerInvariant()))
                        using (BinaryWriter bw = new BinaryWriter(fs))
                            bw.Write(mOutput.ToArray());
                }

                return(ResponseModel.Success(msg: "بارگذاری فایل با موفقیت انجام شد", data: fileName));
            }
            catch (Exception ex)
            {
                return(ResponseModel.Error(msg: "خطایی در بارگذاری فایل رخ داده است.لطفا با پشتیبان سایت تماس بگیرید.", data: ex.Message));
            }
        }
Exemple #17
0
        public async Task <ResponseStructure> UpdatePassword(HttpRequest httpRequest, Microsoft.AspNetCore.Http.HttpResponse response, int userId)
        {
            try
            {
                UserModel userModel = await this.GetById(userId);

                if (userModel == null)
                {
                    return(ResponseModel.Error("Your login token has expired.", new { EXPIREDTOKEN = true }));
                }
                var           data = httpRequest.Headers["PasswordUpdate"];
                var           dec  = Barayand.Common.Services.CryptoJsService.DecryptStringAES(data);
                RegisterModel rm   = JsonConvert.DeserializeObject <RegisterModel>(dec);
                if (!Barayand.Common.Services.CryptoJsService.verifyPassword(userModel.U_Password, rm.CurrentPassword))
                {
                    return(ResponseModel.Error("Current password was incorrect."));
                }
                if (rm.ConfirmPassword != rm.Password)
                {
                    return(ResponseModel.Error("Password and confirm password does not match."));
                }
                userModel.U_Password = Barayand.Common.Services.CryptoJsService.HashPassword(rm.Password);
                response.Cookies.Delete("ValhallaUser");
                return(await this.Update(userModel));
            }
            catch (Exception ex)
            {
                return(ResponseModel.ServerInternalError(data: ex));
            }
        }
Exemple #18
0
 public async Task <ResponseStructure> UploadAudio(IFormFile file, string fireFlag, string loc)
 {
     try
     {
         string ftype = file.ContentType;
         if ((ftype == "audio/mp3" || ftype == "audio/mpeg"))
         {
             string uploadPath = FileLocMapper.LocateMediaFile(fireFlag, loc);
             //long fsize = file[i].Length;
             string fname    = DateTime.UtcNow.Millisecond + UtilesService.GenerateNewRandom() + "." + System.IO.Path.GetExtension(file.FileName).Substring(1);
             var    filePath = Path.Combine(uploadPath, fname);
             using (var stream = new FileStream(filePath, FileMode.Create))
             {
                 await file.CopyToAsync(stream);
             }
             return(ResponseModel.Success(msg: "فایل صوتی با موفقیت آپلود گردید", data: fname));
         }
         else
         {
             return(ResponseModel.Error("نوع فایل ارسال شده صحیح نمیباشد"));
         }
     }
     catch (Exception e)
     {
         return(ResponseModel.Error("خطای ناشناخته در سیستم رخ داده است" + e.Message));
     }
 }
Exemple #19
0
 public async Task <ResponseStructure> LogicalDelete(object id)
 {
     try
     {
         List <ProductCategoryModel> AllCats = (List <ProductCategoryModel>)(await GetAllInside()).Data;
         var Current = AllCats.FirstOrDefault(x => x.PC_Id == (int)id);
         if (Current == null)
         {
             return(ResponseModel.Error("دسته بندی مورد نظر یافت نشد"));
         }
         Current.PC_IsDeleted = true;
         List <ProductCategoryModel> AllChilds = new List <ProductCategoryModel>();
         foreach (var item in GetAllChild((int)id, AllCats))
         {
             item.PC_IsDeleted = true;
             AllChilds.Add(item);
         }
         AllChilds.Add(Current);
         return(await this.UpdateRange(entities : AllChilds));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        public async Task <ActionResult> ReduceWallet(UserModel um)
        {
            try
            {
                var user = await _userrepo.GetById(um.U_Id);

                if (user == null)
                {
                    return(new JsonResult(ResponseModel.Error("کاربر یافت نشد")));
                }
                var doTransaction = await _walletrepo.DecreaseWallet(user.U_Id, um.U_Wallet);

                if (doTransaction.Status)
                {
                    if (user.U_Phone != null && user.U_Phone != "")
                    {
                        await _smsService.WalletAllert(user.U_Phone, 2, um.U_Wallet.ToString("#,#"));
                    }
                    return(new JsonResult(ResponseModel.Success("عملیات با موفقیت انجام گردید")));
                }
                else
                {
                    return(new JsonResult(doTransaction));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Erro in user controller", ex);
                return(new JsonResult(ResponseModel.ServerInternalError(data: ex)));
            }
        }
Exemple #21
0
        public async Task <ResponseStructure> DecreaseWallet(int user, decimal amount)
        {
            try
            {
                UserModel userModel = this._context.Users.FirstOrDefault(x => x.U_Id == user);
                if (userModel.U_Wallet < amount)
                {
                    return(ResponseModel.Error("Account balance is not enough"));
                }
                userModel.U_Wallet = userModel.U_Wallet - amount;
                this._context.Users.Update(userModel);
                await this._context.SaveChangesAsync();

                await this.LogTransaction(new WalletHistoryModel()
                {
                    WH_AdderId         = 0,
                    WH_CustomerId      = user,
                    WH_Amount          = amount,
                    WH_TransactionType = 2,
                    WH_PayType         = 0,
                    WH_PayBankRecip    = ""
                });

                return(ResponseModel.Success("Transaction completed successfully."));
            }
            catch (Exception ex)
            {
                return(ResponseModel.ServerInternalError("Server Internal Error", ex));
            }
        }
Exemple #22
0
        public async Task <ActionResult> AddOfflineRequest()
        {
            try
            {
                StringValues data;
                if (!Request.Headers.TryGetValue("OfflineRequest", out data))
                {
                    return(new JsonResult(ResponseModel.Error("Invalid access detect.")));
                }
                var authorize = Barayand.Common.Services.TokenService.AuthorizeUser(Request);
                if (authorize < 1)
                {
                    return(new JsonResult(ResponseModel.Error("User not logged in.")));
                }

                var dec = Barayand.Common.Services.CryptoJsService.DecryptStringAES(data);
                OfflinRequestModel cm = JsonConvert.DeserializeObject <OfflinRequestModel>(dec);
                cm.O_User = authorize;
                return(new JsonResult(await this._offreqrepo.Insert(cm)));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public IActionResult AddLogic(Domain.Entity.Application application)
        {
            if (string.IsNullOrEmpty(application.Name))
            {
                return(View("Add", ResponseModel.Error("Application Name Can Not Be Null!", application)));
            }
            if (string.IsNullOrEmpty(application.Code))
            {
                return(View("Add", ResponseModel.Error("Application Code Can Not Be Null!", application)));
            }
            //校验code格式
            if (!application.Code.IsAlnum(2, 50))
            {
                return(View("Add", ResponseModel.Error("编码不合法,2-50位且只能包含字母和数字(字母开头)", application)));
            }

            var addResult = applicationService.Add(application);

            if (!addResult.IsSuccess)
            {
                return(View("Add", addResult.ToResponseModel()));
            }

            return(RedirectToAction("List"));
        }
Exemple #24
0
        public IActionResult UpdateJsonDataSourceLogic(DataSource entity)
        {
            var result = Result.Success()
                         .ContinueAssert(!string.IsNullOrEmpty(entity.Name), "名称不能为空")
                         .ContinueAssert(!string.IsNullOrEmpty(entity.Code), "编码不能为空")
                         .ContinueAssert(!string.IsNullOrEmpty(entity.Script), "数据源内容不能为空")
                         .Continue(re =>
            {
                try
                {
                    Newtonsoft.Json.JsonConvert.DeserializeObject(entity.Script);
                }
                catch (System.Exception)
                {
                    return(Result.Error("非法的Json格式."));
                }
                return(re);
            })
                         .Continue(re => _dataSourceService.CheckSameCodeOrName(entity))
                         .Continue(re =>
            {
                entity.ModifyBy = CurrentUserId;
                return(_dataSourceService.Update(entity));
            });

            if (result.IsSuccess)
            {
                return(RedirectToAction("JsonDataSourceList"));
            }
            else
            {
                return(View("UpdateJsonDataSource", ResponseModel.Error(result.Message, entity)));
            }
        }
Exemple #25
0
        public async Task <ResponseStructure> Insert(DynamicPagesContent entity)
        {
            try
            {
                var All = await this.GetAllInside();

                bool exists = All.Any(x => x.PageName == entity.PageName && x.Lang == entity.Lang);
                if (exists)
                {
                    entity.D_Id = All.FirstOrDefault(x => x.PageName == entity.PageName).D_Id;
                    return(await this.Update(entity));
                }
                else
                {
                    await this._context.DynamicPagesContent.AddAsync(entity : entity);

                    await this.CommitAllChanges();

                    return(ResponseModel.Success("operation successfully completed"));
                }
            }
            catch (Exception ex)
            {
                return(ResponseModel.Error(msg: ex.Message, data: ex));
            }
        }
Exemple #26
0
        public IActionResult AddScriptDataSourceLogic(DataSource entity)
        {
            var result = CommonAddCheck("ScriptDataSource", entity)
                         .Continue(re => _triggerScriptService.CompilateAndCheckScript(entity.Script, CurrentApplicationCode))
                         .Continue(re =>
            {
                entity.Code           = $"{CurrentApplicationCode}.ScriptDataSource.{entity.Code}";
                entity.DataSourceType = (int)DataSourceType.Script;
                return(re);
            })
                         .Continue(re =>
            {
                entity.CreateBy = CurrentUserId;
                return(_dataSourceService.Add(entity));
            });

            if (result.IsSuccess)
            {
                return(RedirectToAction("ScriptDataSourceList"));
            }
            else
            {
                return(View("AddScriptDataSource", ResponseModel.Error(result.Message, entity)));
            }
        }
        public IActionResult AddLogic(FieldList entity)
        {
            if (string.IsNullOrEmpty(entity.Name))
            {
                return(View("Add", ResponseModel.Error("名称不能为空", entity)));
            }
            if (string.IsNullOrEmpty(entity.Code))
            {
                return(View("Add", ResponseModel.Error("编码不能为空", entity)));
            }
            //校验code格式
            if (!entity.Code.IsAlnum(2, 50))
            {
                return(View("Add", ResponseModel.Error("编码不合法,2-50位且只能包含字母和数字(字母开头)", entity)));
            }

            //检查编码或名称重复
            var checkResult = fieldListService.CheckSameCodeOrName(CurrentMetaObjectId, entity);

            if (!checkResult.IsSuccess)
            {
                return(View("Add", checkResult.ToResponseModel()));
            }

            entity.MetaObjectId = CurrentMetaObjectId;
            //组合编码
            entity.Code = $"{CurrentMetaObjectCode}.FieldList.{entity.Code}";
            fieldListService.Add(entity);
            return(RedirectToAction("List"));
        }
Exemple #28
0
        public async Task <ResponseStructure> SaveReciptientInfo(HttpRequest httpRequest, HttpResponse httpResponse)
        {
            try
            {
                StringValues data;
                if (!httpRequest.Headers.TryGetValue("ReciptientInfo", out data))
                {
                    return(ResponseModel.Error("Invalid access detect."));
                }
                var dec = Barayand.Common.Services.CryptoJsService.DecryptStringAES(data);
                ReciptientInfoModel     rm     = JsonConvert.DeserializeObject <ReciptientInfoModel>(dec);
                FullPropertyBasketModel basket = new FullPropertyBasketModel();
                string cookie;
                if (httpRequest.Cookies.TryGetValue("Cart", out cookie))
                {
                    if (cookie != null)
                    {
                        var basketInfo = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie);
                        basket = JsonConvert.DeserializeObject <FullPropertyBasketModel>(basketInfo);
                        basket.RecipientInfo = rm;
                    }
                }

                string token = Barayand.Common.Services.CryptoJsService.EncryptStringToAES(JsonConvert.SerializeObject(basket));
                httpResponse.Cookies.Delete("Cart");
                httpResponse.Cookies.Append("Cart", token);
                return(ResponseModel.Success("اطلاعات دریافت کننده سفارش با موفقیت ذخیره گردید."));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error in adding reciver info to customer basket", ex);
                return(ResponseModel.ServerInternalError(data: ex));
            }
        }
Exemple #29
0
        public IActionResult UpdateLogic(InterfaceAggregation entity)
        {
            SetDataSource();

            if (entity.Id == 0)
            {
                return(View("Update", ResponseModel.Error("修改的id传递错误", entity)));
            }
            if (string.IsNullOrEmpty(entity.Name))
            {
                return(View("Update", ResponseModel.Error("名称不能为空", entity)));
            }
            if (string.IsNullOrEmpty(entity.Code))
            {
                return(View("Update", ResponseModel.Error("编码不能为空", entity)));
            }

            //检查编码或名称重复
            var checkResult = interfaceAggregationService.CheckSameCodeOrName(CurrentMetaObjectId, entity);

            if (!checkResult.IsSuccess)
            {
                return(View("Update", checkResult.ToResponseModel()));
            }

            entity.ModifyBy = CurrentUserId;
            interfaceAggregationService.Update(entity);

            return(RedirectToAction("List"));
        }
Exemple #30
0
        public async Task <ResponseStructure> RemoveCartItem(Microsoft.AspNetCore.Http.HttpRequest httpRequest, Microsoft.AspNetCore.Http.HttpResponse httpResponse)
        {
            StringValues data;

            if (!httpRequest.Headers.TryGetValue("RemoveCartItem", out data))
            {
                return(ResponseModel.Error("Invalid access detect."));
            }
            var        dec = Barayand.Common.Services.CryptoJsService.DecryptStringAES(data);
            BasketItem rm  = JsonConvert.DeserializeObject <BasketItem>(dec);

            BasketModel basket = new BasketModel();
            string      cookie;

            if (httpRequest.Cookies.TryGetValue("Cart", out cookie))
            {
                if (cookie != null)
                {
                    var basketInfo = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie);
                    basket           = JsonConvert.DeserializeObject <BasketModel>(basketInfo);
                    basket.CartItems = basket.CartItems.Where(x => x.Product.P_Id != rm.ProductId && x.PrintAble != rm.PrintAble).ToList();
                }
            }
            httpResponse.Cookies.Delete("Cart");

            if (basket.CartItems.Count > 0)
            {
                string token = Barayand.Common.Services.CryptoJsService.EncryptStringToAES(JsonConvert.SerializeObject(basket));

                httpResponse.Cookies.Append("Cart", token);
            }
            return(ResponseModel.Success("Product removed."));
        }