Exemplo n.º 1
0
 public bool SaveArtice(Ld_Info_Artice entity)
 {
     try
     {
         int    systemId  = entity.SystemID;
         string companyId = entity.CompanyID;
         string articeId  = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.InfoArtice);
         if (IsExists(systemId, companyId, articeId))
         {
             throw new Exception("主建ID重复!");
         }
         entity.Hits         = entity.Hits.ToInt();
         entity.Sort         = entity.Sort.ToInt();
         entity.UpNum        = entity.UpNum.ToInt();
         entity.DownNum      = entity.DownNum.ToInt();
         entity.AllowComment = entity.AllowComment.ToBool();
         entity.IsTop        = entity.IsTop.ToBool();
         entity.IsPush       = entity.IsPush.ToBool();
         entity.IsVip        = entity.IsVip.ToBool();
         entity.IsDraft      = entity.IsDraft.ToBool();
         entity.IsDel        = entity.IsDel.ToBool();
         entity.ArticeID     = articeId;
         entity.CreateDate   = DateTime.Now;
         return(Add(entity));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
 public bool SaveNoticeCategory(Ld_Info_NoticeCategory entity)
 {
     try
     {
         var    infoNoticeCategory = PrimaryKeyHelper.PrimaryKeyType.InfoNoticeCategory;
         var    version            = PrimaryKeyHelper.PrimaryKeyLen.V1;
         int    systemId           = entity.SystemID;
         string companyId          = entity.CompanyID;
         string categoryId         = PrimaryKeyHelper.MakePrimaryKey(infoNoticeCategory, version);
         string categoryName       = entity.CategoryName;
         if (IsExists(m => m.SystemID == systemId && m.CompanyID == companyId && m.CategoryID == categoryId))
         {
             throw new Exception("主建ID重复!");
         }
         if (IsExists(m => m.SystemID == systemId && m.CompanyID == companyId && m.CategoryName == categoryName))
         {
             throw new Exception("类别名称已存在!");
         }
         entity.CategoryID = categoryId;
         entity.CreateDate = DateTime.Now;
         return(Add(entity));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 3
0
 public bool SaveBlock(Info_Block entity)
 {
     try
     {
         var    infoBlock     = PrimaryKeyHelper.PrimaryKeyType.InfoBlock;
         var    primaryKeyLen = PrimaryKeyHelper.PrimaryKeyLen.V1;
         int    systemId      = entity.SystemID;
         string companyId     = entity.CompanyID;
         string blockId       = PrimaryKeyHelper.MakePrimaryKey(infoBlock, primaryKeyLen);
         string tags          = entity.Tags;
         bool   state         = entity.State.ToBool();
         if (string.IsNullOrEmpty(tags))
         {
             throw new Exception("块标签不能为空!");
         }
         bool verifyTags = IsExists(m => m.SystemID == systemId && m.CompanyID == companyId && m.Tags == tags);
         if (verifyTags)
         {
             throw new Exception("块标签不能重复!");
         }
         entity.BlockID    = blockId;
         entity.State      = state;
         entity.CreateDate = DateTime.Now;
         return(Add(entity));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 4
0
        public IActionResult Register(string uuid, [FromBody]JObject fromValue)
        {
            long logId = 0;
            try
            {
                int systemId = SystemID;
                logId = BaseApiManager.SaveLogs(uuid, fromValue);
                if (!IsUuid(uuid)) { return Error(logId, "verify uuid fail!"); }
                bool isParams = IsRegisterParams(fromValue);
                var entity = GetInterfaceAccountByUuid(uuid);
                string companyId = entity.CompanyID;
                string memberId = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.MemberAccount);
                string phone = GetJObjectValue(fromValue, "phone");
                string password = GetJObjectValue(fromValue, "password");
                string ipAddress = Net.Ip;
                if (!Utility.IsMobilePhone(phone))
                    return Error(logId, "verify phone fail!");

                var result = AccountService.SaveAccountRegisterPro(systemId, companyId, memberId, AlgorithmHelper.MD5(password), phone, ipAddress);
                if (result)
                    return Success(logId, "ok");
                else
                    return Error(logId, "fail");
            }
            catch (Exception ex)
            {
                return Error(logId, ex.Message);
            }
        }
Exemplo n.º 5
0
 public JsonResult SaveFileSingle()
 {
     try
     {
         var  files = Request.Form.Files;
         int  count = files.Count;
         long size  = files.Sum(f => f.Length);
         if (count == 0)
         {
             return(Error("上传文件不能为空!"));
         }
         if (size == 0)
         {
             return(Error("上传文件大小不能为0字节!"));
         }
         var    formFile    = files.FirstOrDefault();
         var    name        = formFile.Name;
         var    fileSize    = formFile.Length;
         var    fileName    = formFile.FileName;
         string uploadPath  = CreateUploadPath(SystemID, CompanyID, fileName);
         string newFileName = CreateFileName(fileName);
         var    filePath    = string.Format("{0}\\{1}", uploadPath, newFileName);
         string src         = ToRelativePath(filePath);
         string url         = ToAbsoluteUri(filePath);
         string mediaId     = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.BasicsMedia);
         var    media       = new Basics_Media()
         {
             SystemID      = SystemID,
             CompanyID     = CompanyID,
             MediaID       = mediaId,
             FileName      = fileName,
             FileExtension = Path.GetExtension(fileName).ToLower(),
             FileSize      = fileSize,
             Url           = url,
             Src           = src,
         };
         var data = new { mediaid = mediaId, name = fileName, size = fileSize, url, src };
         if (formFile.Length > 0)
         {
             using (var stream = new FileStream(filePath, FileMode.Create))
             {
                 formFile.CopyTo(stream);
                 stream.Flush();
             }
         }
         bool result = MediaService.SaveMedia(media);
         if (result)
         {
             return(Success("ok", new { count, size, file = data }));
         }
         else
         {
             return(Error("upload fail!"));
         }
     }
     catch (Exception ex)
     {
         return(Error(ex.Message));
     }
 }
Exemplo n.º 6
0
        public bool SaveAdvertisement(Ld_Extend_Advertisement entity, List <Ld_Extend_AdvertisementDetails> lists)
        {
            try
            {
                var    advertisement        = PrimaryKeyHelper.PrimaryKeyType.ExtendAdvertisement;
                var    advertisementDetails = PrimaryKeyHelper.PrimaryKeyType.ExtendAdvertisementDetails;
                var    version         = PrimaryKeyHelper.PrimaryKeyLen.V1;
                string advertisementId = PrimaryKeyHelper.MakePrimaryKey(advertisement, version);

                entity.AdvertisementID = advertisementId;
                entity.Sort            = entity.Sort.ToInt();
                entity.State           = entity.State.ToBool();
                entity.CreateDate      = DateTime.Now;

                if (lists == null)
                {
                    throw new Exception("广告列表不能为空!");
                }
                List <Ld_Extend_AdvertisementDetails> details = new List <Ld_Extend_AdvertisementDetails>();
                foreach (var m in lists)
                {
                    string advertisementDetailsId = PrimaryKeyHelper.MakePrimaryKey(advertisementDetails, version);
                    m.SystemID        = entity.SystemID;
                    m.CompanyID       = entity.CompanyID;
                    m.DetailsID       = advertisementDetailsId;
                    m.AdvertisementID = advertisementId;
                    m.Sort            = m.Sort.ToInt();
                    m.State           = m.State.ToBool();
                    m.CreateDate      = DateTime.Now;
                    details.Add(m);
                }

                int intnum    = 0;
                var dbContext = new DAL.BaseDAL(LdCmsDbEntitiesContext);
                using (var db = dbContext.DbEntities())
                {
                    using (var trans = db.Database.BeginTransaction())
                    {
                        try
                        {
                            dbContext.Add(entity);
                            dbContext.Add(details);
                            intnum = db.SaveChanges();
                            trans.Commit();
                        }
                        catch (Exception)
                        {
                            trans.Rollback();
                        }
                        return(intnum > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 7
0
 private string CreateTableID()
 {
     try
     {
         return(PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.Table, PrimaryKeyHelper.PrimaryKeyLen.V1));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 8
0
 public bool SaveMessageBoard(Ld_Service_MessageBoard entity)
 {
     try
     {
         string messageId = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.ServiceMessageBoard);
         entity.MessageID  = messageId;
         entity.IsTop      = false;
         entity.State      = false;
         entity.CreateDate = DateTime.Now;
         return(Add(entity));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 9
0
        public void CreateTable <T>(T t) where T : class
        {
            try
            {
                string tableID    = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.Table, PrimaryKeyHelper.PrimaryKeyLen.V1);
                string tableName  = typeof(T).Name;
                string primaryKey = "SystemID";
                string Account    = "sys";
                string NickName   = "系统生成";

                Log_Table entity = new Log_Table();
                entity.TableID    = tableID;
                entity.TableName  = tableName;
                entity.PrimaryKey = primaryKey;
                entity.Account    = Account;
                entity.NickName   = NickName;

                List <Log_TableDetails> lists = new List <Log_TableDetails>();
                PropertyInfo[]          pi    = typeof(T).GetProperties();
                foreach (PropertyInfo p in pi)
                {
                    string columnName = p.Name.ToString();  //得到属性的名称
                    Type   columnType = p.PropertyType;     //得到属性的类型
                    if (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        columnType = p.PropertyType.GetGenericArguments()[0];
                    }
                    lists.Add(new Log_TableDetails()
                    {
                        TableID        = tableID,
                        TableName      = tableName,
                        ColumnName     = columnName,
                        ColumnDataType = columnType.Name,
                        Account        = Account,
                        NickName       = NickName,
                    });
                }
                TableService.SaveTable(entity);
                TableDetailsService.SaveTableDetails(lists);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 10
0
 public bool SavePage(Info_Page entity)
 {
     try
     {
         var    infoPage      = PrimaryKeyHelper.PrimaryKeyType.InfoPage;
         var    primaryKeyLen = PrimaryKeyHelper.PrimaryKeyLen.V1;
         string pageId        = PrimaryKeyHelper.MakePrimaryKey(infoPage, primaryKeyLen);
         int    sort          = entity.Sort.ToInt();
         entity.PageID     = pageId;
         entity.Sort       = sort;
         entity.CreateDate = DateTime.Now;
         return(Add(entity));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
 public bool SaveAdvertisementDetails(Ld_Extend_AdvertisementDetails entity)
 {
     try
     {
         var    advertisementDetails = PrimaryKeyHelper.PrimaryKeyType.ExtendAdvertisementDetails;
         var    version = PrimaryKeyHelper.PrimaryKeyLen.V1;
         string advertisementDetailsId = PrimaryKeyHelper.MakePrimaryKey(advertisementDetails, version);
         entity.DetailsID  = advertisementDetailsId;
         entity.Sort       = entity.Sort.ToInt();
         entity.State      = entity.State.ToBool();
         entity.CreateDate = DateTime.Now;
         return(Add(entity));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 12
0
 public bool SaveLinkGroup(Ld_Extend_LinkGroup entity)
 {
     try
     {
         var    linkGroup   = PrimaryKeyHelper.PrimaryKeyType.ExtendLinkGroup;
         var    version     = PrimaryKeyHelper.PrimaryKeyLen.V1;
         string linkGroupId = PrimaryKeyHelper.MakePrimaryKey(linkGroup, version);
         entity.GroupID    = linkGroupId;
         entity.Sort       = entity.Sort.ToInt();
         entity.IsExternal = entity.IsExternal.ToBool();
         entity.State      = entity.State.ToBool();
         entity.CreateDate = DateTime.Now;
         return(Add(entity));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 13
0
 public bool SaveNotice(Ld_Info_Notice entity)
 {
     try
     {
         int    systemId  = entity.SystemID;
         string companyId = entity.CompanyID;
         string noticeId  = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.InfoNotice);
         if (IsExists(systemId, companyId, noticeId))
         {
             throw new Exception("主建ID重复!");
         }
         entity.NoticeID   = noticeId;
         entity.CreateDate = DateTime.Now;
         return(Add(entity));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 14
0
        public bool SaveLink(Extend_Link entity)
        {
            try
            {
                var    link     = PrimaryKeyHelper.PrimaryKeyType.ExtendLink;
                var    version  = PrimaryKeyHelper.PrimaryKeyLen.V1;
                string linkId   = PrimaryKeyHelper.MakePrimaryKey(link, version);
                string logo     = entity.Logo;
                int    typeId   = string.IsNullOrEmpty(logo) ? 1 : 2;
                string typeName = string.IsNullOrEmpty(logo) ? "文字" : "LOGO";

                entity.LinkID     = linkId;
                entity.TypeID     = typeId.ToByte();
                entity.TypeName   = typeName;
                entity.Sort       = entity.Sort.ToInt();
                entity.State      = entity.State.ToBool();
                entity.CreateDate = DateTime.Now;
                return(Add(entity));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 15
0
        public bool SaveAccount(Ld_Member_Account entity)
        {
            try
            {
                int      systemId   = entity.SystemID;
                string   companyId  = entity.CompanyID;
                string   memberId   = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.MemberAccount, PrimaryKeyHelper.PrimaryKeyLen.V2);
                DateTime CreateDate = DateTime.Now;
                if (IsAccount(systemId, companyId, memberId))
                {
                    throw new Exception("会员ID已存在!");
                }
                entity.MemberID   = memberId;
                entity.State      = true;
                entity.IsDel      = false;
                entity.CreateDate = CreateDate;

                return(Add(entity));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 16
0
        public bool SaveClass(Info_Class entity)
        {
            try
            {
                var    infoClass     = PrimaryKeyHelper.PrimaryKeyType.InfoClass;
                var    primaryKeyLen = PrimaryKeyHelper.PrimaryKeyLen.V1;
                int    systemId      = entity.SystemID;
                string companyId     = entity.CompanyID;
                string classId       = PrimaryKeyHelper.MakePrimaryKey(infoClass, primaryKeyLen);
                string className     = entity.ClassName;
                int    classType     = entity.ClassType.ToInt();
                string parentId      = string.IsNullOrEmpty(entity.ParentID) ? "0" : entity.ParentID;
                bool   state         = entity.State.ToBool();

                if (parentId != "0")
                {
                    bool verifyParentId = IsExists(m => m.SystemID == systemId && m.CompanyID == companyId && m.ClassID == parentId);
                    if (!verifyParentId)
                    {
                        throw new Exception("上级分类ID不存在!");
                    }
                }
                bool verifyClassName = IsExists(m => m.SystemID == systemId && m.CompanyID == companyId && m.ParentID == parentId && m.ClassName == className);
                if (verifyClassName)
                {
                    throw new Exception("分类名称已存在!");
                }
                if (parentId == "0")
                {
                    entity.ParentID   = "0";
                    entity.ParentPath = "0";
                    entity.ClassRank  = 1;
                    entity.OrderID    = 0;
                    entity.OrderPath  = classId;
                }
                else
                {
                    var    entityClass = Find(m => m.SystemID == systemId && m.CompanyID == companyId && m.ClassID == parentId);
                    int    classRank   = entityClass.ClassRank.ToInt();
                    string parentPath  = entityClass.ParentPath;
                    string orderPath   = entityClass.OrderPath;
                    entity.ParentID   = parentId;
                    entity.ParentPath = string.Format("{0},{1}", parentPath, parentId);
                    entity.ClassRank  = (classRank + 1).ToByte();
                    entity.OrderID    = 0;
                    entity.OrderPath  = string.Format("{0}{1}", orderPath, classId);
                }
                entity.ClassID    = classId;
                entity.State      = state;
                entity.CreateDate = DateTime.Now;


                var    infoPage        = PrimaryKeyHelper.PrimaryKeyType.InfoPage;
                var    infoPageVersion = PrimaryKeyHelper.PrimaryKeyLen.V1;
                string pageId          = PrimaryKeyHelper.MakePrimaryKey(infoPage, infoPageVersion);
                var    entityPage      = new Info_Page()
                {
                    SystemID   = systemId,
                    CompanyID  = companyId,
                    PageID     = pageId,
                    Title      = entity.ClassName,
                    ClassID    = entity.ClassID,
                    ClassName  = entity.ClassName,
                    Sort       = 0,
                    State      = true,
                    CreateDate = DateTime.Now
                };

                int intnum    = 0;
                var dbContext = new DAL.BaseDAL(CTMSContext);
                using (var db = dbContext.DbEntities())
                {
                    //using (var trans = db.Database.BeginTransaction())
                    //{
                    //    try
                    //    {
                    //        dbContext.Add(entity);
                    //        if (classType == 1)
                    //            dbContext.Add(entityPage);
                    //        intnum = db.SaveChanges();
                    //        trans.Commit();
                    //    }
                    //    catch (Exception)
                    //    {
                    //        trans.Rollback();
                    //    }
                    //    return intnum > 0;
                    //}
                    db.Orm.Transaction(() =>
                    {
                        dbContext.Add(entity);
                        if (classType == 1)
                        {
                            dbContext.Add(entityPage);
                        }
                        intnum = db.SaveChanges();
                    });
                    return(intnum > 0);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 17
0
        public bool UpdateAdvertisement(Extend_Advertisement entity, List <Extend_AdvertisementDetails> lists)
        {
            try
            {
                var    advertisementDetails = PrimaryKeyHelper.PrimaryKeyType.ExtendAdvertisementDetails;
                var    version         = PrimaryKeyHelper.PrimaryKeyLen.V1;
                int    systemId        = entity.SystemID;
                string companyId       = entity.CompanyID;
                string advertisementId = entity.AdvertisementID;
                entity.Sort       = entity.Sort.ToInt();
                entity.State      = entity.State.ToBool();
                entity.CreateDate = DateTime.Now;

                if (lists == null)
                {
                    throw new Exception("广告列表不能为空!");
                }
                List <Extend_AdvertisementDetails> details = new List <Extend_AdvertisementDetails>();
                foreach (var m in lists)
                {
                    string advertisementDetailsId = PrimaryKeyHelper.MakePrimaryKey(advertisementDetails, version);
                    m.SystemID        = entity.SystemID;
                    m.CompanyID       = entity.CompanyID;
                    m.DetailsID       = advertisementDetailsId;
                    m.AdvertisementID = advertisementId;
                    m.Sort            = m.Sort.ToInt();
                    m.State           = m.State.ToBool();
                    m.CreateDate      = DateTime.Now;
                    details.Add(m);
                }
                var expression = ExtLinq.True <Extend_AdvertisementDetails>();
                expression = expression.And(m => m.SystemID == systemId && m.CompanyID == companyId && m.AdvertisementID == advertisementId);

                int intnum    = 0;
                var dbContext = new DAL.BaseDAL(CTMSContext);
                using (var db = dbContext.DbEntities())
                {
                    //using (var trans = db.Database.BeginTransaction())
                    //{
                    //    try
                    //    {
                    //        dbContext.Update(entity);
                    //        dbContext.Delete(expression);
                    //        dbContext.Add(details);
                    //        intnum = db.SaveChanges();
                    //        trans.Commit();
                    //    }
                    //    catch (Exception)
                    //    {
                    //        trans.Rollback();
                    //    }
                    //    return intnum > 0;
                    //}
                    db.Orm.Transaction(() =>
                    {
                        dbContext.Update(entity);
                        dbContext.Delete(expression);
                        dbContext.Add(details);
                        intnum = db.SaveChanges();
                    });
                    return(intnum > 0);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 18
0
        public IActionResult SaveImageCode(string access_token)
        {
            try
            {
                int systemId = SystemID;
                if (!IsAccessToken(access_token))
                {
                    return(Error("验证token失败!"));
                }
                var entity = AccountService.GetAccountByAccessTokenPro(systemId, access_token);
                if (entity == null)
                {
                    return(Error("验证会员资料失败!"));
                }
                if (string.IsNullOrEmpty(entity.CompanyID))
                {
                    return(Error("验证会员资料失败!"));
                }
                string companyId = entity.CompanyID;
                string memberId  = entity.MemberID;

                string base64String = Accessor.HttpContext.Request.GetInputStream();
                string imageCode    = ImageHelper.GetImageCode(base64String);
                long   fileSize     = imageCode.Length;
                string fileName     = string.Format("{0}.{1}", GeneralCodeHelper.GetRandomInt(8), ImageHelper.GetImageExtension(base64String));
                string uploadPath   = CreateUploadPath(systemId, companyId, fileName);
                string newFileName  = CreateFileName(fileName);
                var    filePath     = string.Format("{0}\\{1}", uploadPath, newFileName);
                string src          = ToRelativePath(filePath);
                string url          = ToAbsoluteUri(filePath);
                string mediaId      = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.BasicsMedia);
                var    media        = new Ld_Basics_Media()
                {
                    SystemID      = systemId,
                    CompanyID     = companyId,
                    MediaID       = mediaId,
                    FileName      = fileName,
                    FileExtension = Path.GetExtension(fileName).ToLower(),
                    FileSize      = fileSize,
                    Url           = url,
                    Src           = src,
                };
                var data = new { mediaid = mediaId, name = fileName, size = fileSize, url, src };
                if (fileSize > 0)
                {
                    string savePath = ImageHelper.Base64StringToImage(filePath, base64String);
                }
                int result = MediaService.SaveMediaMember(memberId, media);
                if (result > 0)
                {
                    return(Success("ok", new { count = 1, size = fileSize, file = data }));
                }
                else
                {
                    return(Error("upload fail!"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
Exemplo n.º 19
0
        public IActionResult SaveFileSingle(string access_token)
        {
            try
            {
                int systemId = SystemID;
                if (!IsAccessToken(access_token))
                {
                    return(Error("验证token失败!"));
                }
                var entity = AccountService.GetAccountByAccessTokenPro(systemId, access_token);
                if (entity == null)
                {
                    return(Error("验证会员资料失败!"));
                }
                if (string.IsNullOrEmpty(entity.CompanyID))
                {
                    return(Error("验证会员资料失败!"));
                }
                string companyId = entity.CompanyID;
                string memberId  = entity.MemberID;

                var  files = Request.Form.Files;
                int  count = files.Count;
                long size  = files.Sum(f => f.Length);
                if (count == 0)
                {
                    return(Error("上传文件不能为空!"));
                }
                if (size == 0)
                {
                    return(Error("上传文件大小不能为0字节!"));
                }

                var formFile = files.FirstOrDefault();

                var    name        = formFile.Name;
                var    fileSize    = formFile.Length;
                var    fileName    = formFile.FileName;
                string uploadPath  = CreateUploadPath(systemId, companyId, fileName);
                string newFileName = CreateFileName(fileName);
                var    filePath    = string.Format("{0}\\{1}", uploadPath, newFileName);
                string src         = ToRelativePath(filePath);
                string url         = ToAbsoluteUri(filePath);
                string mediaId     = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.BasicsMedia);
                var    media       = new Ld_Basics_Media()
                {
                    SystemID      = systemId,
                    CompanyID     = companyId,
                    MediaID       = mediaId,
                    FileName      = fileName,
                    FileExtension = Path.GetExtension(fileName).ToLower(),
                    FileSize      = fileSize,
                    Url           = url,
                    Src           = src,
                };
                var data = new { mediaid = mediaId, name = fileName, size = fileSize, url, src };
                if (formFile.Length > 0)
                {
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        formFile.CopyTo(stream);
                        stream.Flush();
                    }
                }
                int result = MediaService.SaveMediaMember(memberId, media);
                if (result > 0)
                {
                    return(Success("ok", new { count, size, file = data }));
                }
                else
                {
                    return(Error("upload fail!"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
        public JsonResult Save(string memberId)
        {
            try
            {
                if (!IsSavePermission(memberId))
                {
                    return(Error("您没有操作权限,请联系系统管理员!"));
                }

                string fRankId      = GetFormValue("fRankId");
                string fRankName    = GetFormValue("fRankName");
                string fCompanyName = GetFormValue("CompanyName");
                string fName        = GetFormValue("fName");
                string fSex         = GetFormValue("fSex");
                string fPhone       = GetFormValue("fPhone");
                string fEmail       = GetFormValue("fEmail");
                string fAddress     = GetFormValue("fAddress");
                string fRemark      = GetFormValue("fRemark");
                string fState       = GetFormValue("fState");
                string fMemberId    = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.MemberAccount);

                if (!Utility.IsMobilePhone(fPhone))
                {
                    return(Error("手机号码格式错误!"));
                }

                string password = AlgorithmHelper.MD5(fPhone.Right(8));

                Ld_Member_Account entity = new Ld_Member_Account()
                {
                    SystemID          = SystemID,
                    CompanyID         = CompanyID,
                    MemberID          = fMemberId,
                    RankID            = fRankId,
                    RankName          = fRankName,
                    UserName          = fPhone,
                    Password          = password,
                    CompanyName       = fCompanyName,
                    Name              = fName,
                    NickName          = fName,
                    Sex               = fSex.ToByte(),
                    Phone             = fPhone,
                    Email             = fEmail,
                    Address           = fAddress,
                    Remark            = fRemark,
                    State             = fState.ToBool(),
                    TotalPoints       = 0,
                    TotalAmount       = 0.00.ToDecimal(),
                    TotalConsumption  = 0.00.ToDecimal(),
                    RegisterIpAddress = Net.Ip,
                    RegisterTime      = DateTime.Now,
                    IsDel             = false,
                    CreateDate        = DateTime.Now
                };

                bool result = false;
                if (string.IsNullOrEmpty(memberId))
                {
                    result = AccountService.SaveAccount(entity);
                }
                else
                {
                    var m = AccountService.GetAccount(SystemID, CompanyID, memberId);
                    m.RankID      = fRankId;
                    m.RankName    = fRankName;
                    m.UserName    = fPhone;
                    m.CompanyName = fCompanyName;
                    m.Name        = fName;
                    m.NickName    = fName;
                    m.Sex         = fSex.ToByte();
                    m.Phone       = fPhone;
                    m.Email       = fEmail;
                    m.Address     = fAddress;
                    m.Remark      = fRemark;
                    m.State       = fState.ToBool();
                    result        = AccountService.UpdateAccount(m);
                }
                if (result)
                {
                    return(Success("ok"));
                }
                else
                {
                    return(Error("fail"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }