Пример #1
0
        public List <AddressItemModel> List(ApiCall apiCall)
        {
            var user  = apiCall.Context.User;
            var orgdb = Kooboo.Mail.Factory.DBFactory.OrgDb(user.CurrentOrgId);

            var addlist = orgdb.EmailAddress.Query().Where(o => o.UserId == user.Id).SelectAll();

            return(addlist.Select(o => AddressItemModel.FromAddress(o)).OrderBy(o => o.Address).ToList());
        }
Пример #2
0
        public List <AddressItemModel> List(ApiCall apiCall)
        {
            if (EmailForwardManager.RequireForward(apiCall.Context))
            {
                return(EmailForwardManager.Get <List <AddressItemModel> >(this.ModelName, nameof(EmailAddressApi.List), apiCall.Context.User));
            }
            var user  = apiCall.Context.User;
            var orgdb = Kooboo.Mail.Factory.DBFactory.OrgDb(user.CurrentOrgId);

            var addlist = orgdb.EmailAddress.Query().Where(o => o.UserId == user.Id).SelectAll();

            return(addlist.Select(o => AddressItemModel.FromAddress(o)).OrderBy(o => o.Address).ToList());
        }
Пример #3
0
        public object Post(ApiCall apiCall)
        {
            if (EmailForwardManager.RequireForward(apiCall.Context))
            {
                var json = Kooboo.Lib.Helper.JsonHelper.Serialize(apiCall.Context.Request.Model);
                return(EmailForwardManager.Post <object>(this.ModelName, nameof(EmailAddressApi.Post), apiCall.Context.User, json, null));
            }

            var model   = apiCall.Context.Request.Model as AddressModel;
            var user    = apiCall.Context.User;
            var orgdb   = Kooboo.Mail.Factory.DBFactory.OrgDb(user.CurrentOrgId);
            var address = new EmailAddress
            {
                Address        = model.ToEmail().ToLower(),
                ForwardAddress = model.ForwardAddress,
                AddressType    = model.AddressType,
                UserId         = user.Id
            };

            if (!Kooboo.Mail.Utility.AddressUtility.IsValidEmailAddress(address.Address))
            {
                return(new Kooboo.Api.ApiResponse.JsonResponse
                {
                    Success = false,
                    Messages = new List <string> {
                        Kooboo.Data.Language.Hardcoded.GetValue("Invalid address format", apiCall.Context)
                    }
                });
            }

            if (address.AddressType == EmailAddressType.Forward)
            {
                address.ForwardAddress = address.ForwardAddress.ToLower();
                if (address.Address == address.ForwardAddress)
                {
                    return(new Kooboo.Api.ApiResponse.JsonResponse
                    {
                        Success = false,
                        Messages = new List <string> {
                            "Forward to address should not be same as forward from"
                        }
                    });
                }
            }

            orgdb.EmailAddress.AddOrUpdate(address);

            return(AddressItemModel.FromAddress(address));
        }