Ejemplo n.º 1
0
        public ActionResult Save(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CustomerFormViewModel
                {
                    Customer        = customer,
                    MembershipTypes = db.MembershipTypes.ToList()
                };

                return(View("CustomerForm", viewModel));
            }

            if (customer.Id == 0)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
            }
            else
            {
                var customerInDb = db.Customers.Single(c => c.Id == customer.Id);
                customerInDb.Name     = customer.Name;
                customerInDb.Birthday = customer.Birthday;
                customerInDb.IsSubscribedToNewsletter = customer.IsSubscribedToNewsletter;
                customerInDb.MembershipTypeId         = customer.MembershipTypeId;
            }
            db.SaveChanges();

            return(RedirectToAction("Index", "Customers"));
        }
        public IHttpActionResult CreateCustomer(CustomerDto customerdto)
        {
            if (!ModelState.IsValid)
                return BadRequest();

            var customer = Mapper.Map<CustomerDto, Customer>(customerdto);
            db.Customers.Add(customer);
            db.SaveChanges();

            customerdto.Id = customer.Id;

            return Created(new Uri(Request.RequestUri + "/" + customer.Id), customerdto);
        }
Ejemplo n.º 3
0
 public IHttpActionResult SettingsSave(dynamic data)
 {
     try
     {
         foreach (var file in data.files)
         {
             foreach (var item in data.list)
             {
                 if (item.DictKey.ToString() == file.propertyName.ToString())
                 {
                     item.DictValue = UpFileClass.FileSave(file.filePath.ToString(), item.DictValue.ToString(), (int)file.fileType);
                 }
             }
         }
         Dbctx.GgcmsDictionaries
         .ToList()
         .ForEach(x =>
         {
             foreach (var item in data.list)
             {
                 if (x.Id == (int)item.Id)
                 {
                     x.DictValue = item.DictValue.ToString();
                 }
             }
         });
         Dbctx.SaveChanges();
         CacheHelper.RemoveAllCache(CacheTypeNames.SysConfigs.ToString());
         return(Ok(data.list));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 4
0
        public IHttpActionResult ModifyPassword(dynamic passData)
        {
            string oldPassword = passData.oldPassword.ToString();
            string newPassword = passData.newPassword.ToString();
            string rePassword  = passData.rePassword.ToString();
            string sessionKey  = SystemEnums.login_user.ToString();

            if (Session[sessionKey] != null)
            {
                GgcmsMembers m    = Session[sessionKey] as GgcmsMembers;
                GgcmsMembers info = Dbctx.GgcmsMembers.Find(m.Id);
                if (info.PassWord != oldPassword)
                {
                    return(BadRequest("原密码不正确"));
                }
                else if (newPassword != rePassword)
                {
                    return(BadRequest("新密码和确认密码不同"));
                }
                else
                {
                    info.PassWord = newPassword;
                    var ent = Dbctx.Entry(info);
                    ent.Property("PassWord").IsModified = true;
                    Dbctx.SaveChanges();
                    Session.RemoveAll();
                }
                return(Ok(info));
            }
            return(BadRequest("请先登录"));
        }
        public IHttpActionResult CreateMovie(MovieDto movieDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var movie = Mapper.Map <MovieDto, Movie>(movieDto);

            db.Movies.Add(movie);
            db.SaveChanges();

            movieDto.Id = movie.Id;

            return(Created(new Uri(Request.RequestUri + "/" + movie.Id), movieDto));
        }
        public ActionResult Save(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MovieFormViewModel
                {
                    Movie  = movie,
                    Genres = db.Genres.ToList()
                };

                return(View("MovieForm", viewModel));
            }

            if (movie.Id == 0)
            {
                db.Movies.Add(movie);
            }
            else
            {
                var movieInDb = db.Movies.Single(c => c.Id == movie.Id);

                movieInDb.Name    = movie.Name;
                movieInDb.GenreId = movie.GenreId;
            }

            db.SaveChanges();

            return(RedirectToAction("Index", "Movies"));
        }
Ejemplo n.º 7
0
        // DELETE: api/GgcmsCategories/5
        public IHttpActionResult Delete(int id)
        {
            GgcmsArticles info = Dbctx.GgcmsArticles.Find(id);

            if (info == null)
            {
                return(BadRequest("信息不存在"));
            }

            //删除关联模型数据
            var category = dbHelper.Categories(Math.Abs(info.Category_Id));

            if (category != null)
            {
                if (category.ExtModelId > 0)
                {
                    ExtendModule.Delete(info.Id, category.ExtModelId);
                }
                updateArticleNumber(info.Category_Id, -1);
            }
            Dbctx.GgcmsArticles.Remove(info);
            //删除关联附件
            Dbctx.GgcmsAttachments.RemoveRange(Dbctx.GgcmsAttachments.Where(x => x.Articles_Id == info.Id));
            //删除关联分页
            Dbctx.GgcmsArticlePages.RemoveRange(Dbctx.GgcmsArticlePages.Where(x => x.Article_Id == info.Id));
            Dbctx.SaveChanges();
            ClearCache();
            CacheHelper.RemoveAllCache(CacheTypeNames.Categorys);
            return(Ok(info));
        }
Ejemplo n.º 8
0
        public IHttpActionResult MultDelete(int[] ids)
        {
            var query = Dbctx.GgcmsArticles.Where(x => ids.Contains(x.Id));

            foreach (GgcmsArticles item in query.ToList())
            {
                //删除关联附件
                var attalist = Dbctx.GgcmsAttachments.Where(x => x.Articles_Id == item.Id);
                Dbctx.GgcmsAttachments.RemoveRange(attalist);
                //删除关联模型数据
                var category = dbHelper.Categories(Math.Abs(item.Category_Id));
                if (category != null)
                {
                    if (category.ExtModelId > 0)
                    {
                        ExtendModule.Delete(item.Id, category.ExtModelId);
                    }
                    updateArticleNumber(item.Category_Id, -1);
                }
                //删除关联分页
                Dbctx.GgcmsArticlePages.RemoveRange(Dbctx.GgcmsArticlePages.Where(x => x.Article_Id == item.Id));
            }
            Dbctx.GgcmsArticles.RemoveRange(query);
            int c = Dbctx.SaveChanges();

            ClearCache();
            CacheHelper.RemoveAllCache(CacheTypeNames.Categorys);
            return(Ok(c));
        }
Ejemplo n.º 9
0
        public IHttpActionResult CategorySortSave(dynamic[] list)
        {
            try {
                Dbctx.GgcmsCategories
                .ToList()
                .ForEach(x => {
                    foreach (var item in list)
                    {
                        if (x.Id == (int)item.Id)
                        {
                            x.OrderId  = (int)item.OrderId;
                            x.ParentId = (int)item.ParentId;
                        }
                    }
                });

                int c = Dbctx.SaveChanges();
                ClearCache();
                CacheHelper.RemoveAllCache(CacheTypeNames.Categorys);
                return(Ok(c));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 10
0
        // PUT: api/GgcmsCategories/5
        public IHttpActionResult Edit(GgcmsMembers info)
        {
            var oldinfo = Dbctx.GgcmsMembers.Find(info.Id);

            if (oldinfo == null)
            {
                return(BadRequest("信息不存在"));
            }
            Dbctx.Entry(oldinfo).State = EntityState.Detached;

            //Dbctx.GgcmsMembers.Attach(info);
            //Dbctx.Entry(info).Property("goods_name").IsModified = true;
            //密码为空时,使用旧密码
            if (string.IsNullOrWhiteSpace(info.PassWord))
            {
                info.PassWord = oldinfo.PassWord;
            }
            var ent = Dbctx.Entry(info);

            ent.State = EntityState.Modified;
            Dbctx.SaveChanges();
            ClearCache();
            info.PassWord = "";
            return(Ok(info));
        }
Ejemplo n.º 11
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsStyles styleInfo)
        {
            string staticDir   = ConfigurationManager.AppSettings["StaticDir"].ToString();
            string styleDir    = ConfigurationManager.AppSettings["StyleDir"].ToString();
            string root        = "/" + staticDir + "/" + styleDir + "/" + styleInfo.Folder;
            string templateDir = ConfigurationManager.AppSettings["TemplateDir"].ToString();

            templateDir = "/Views/" + templateDir + "/" + styleInfo.Folder;

            string rootpath     = HttpContext.Current.Server.MapPath("~" + root);
            string templatePath = HttpContext.Current.Server.MapPath("~" + templateDir);

            if (Directory.Exists(rootpath) || Directory.Exists(templatePath))
            {
                BadRequest("文件夹已经存在");
            }
            else
            {
                Directory.CreateDirectory(rootpath);
                Directory.CreateDirectory(templatePath);
            }
            var result = Dbctx.GgcmsStyles.Add(styleInfo);

            Dbctx.SaveChanges();
            ClearCache();
            return(Ok(result));
        }
Ejemplo n.º 12
0
        public IHttpActionResult MultDelete(int[] ids)
        {
            string staticDir = ConfigurationManager.AppSettings["StaticDir"].ToString();
            string styleDir  = ConfigurationManager.AppSettings["StyleDir"].ToString();

            styleDir = "/" + staticDir + "/" + styleDir + "/";
            string templateDir = ConfigurationManager.AppSettings["TemplateDir"].ToString();

            templateDir = "/Views/" + templateDir + "/";

            try
            {
                var query = Dbctx.GgcmsStyles.Where(x => ids.Contains(x.Id));
                foreach (var item in query.ToList())
                {
                    GgcmsStyles styleInfo    = item as GgcmsStyles;
                    string      stylePath    = HttpContext.Current.Server.MapPath("~" + styleDir + styleInfo.Folder);
                    string      templatePath = HttpContext.Current.Server.MapPath("~" + templateDir + styleInfo.Folder);
                    Directory.Delete(stylePath, true);
                    Directory.Delete(templatePath, true);
                }
                Dbctx.GgcmsStyles.RemoveRange(query);
                int c = Dbctx.SaveChanges();
                ClearCache();
                return(Ok(c));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 13
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsPowers info)
        {
            var result = Dbctx.GgcmsPowers.Add(info);

            Dbctx.SaveChanges();
            ClearCache();
            return(Ok(result));
        }
Ejemplo n.º 14
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsAdverts info)
        {
            UpFileClass.FileSave(info, info.files.FindAll(x => x.fileType != 3));
            var result = Dbctx.GgcmsAdverts.Add(info);

            Dbctx.SaveChanges();
            ClearCache();
            return(Ok(result));
        }
Ejemplo n.º 15
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsArticles info)
        {
            //提交除附加模型外的文件-标题图,内容中的图
            UpFileClass.FileSave(info, info.files.FindAll(x => x.fileType != 3));
            info.CreateTime = DateTime.Now;
            updateArticleNumber(info.Category_Id, 1);
            CacheHelper.RemoveAllCache(CacheTypeNames.Categorys);
            if (info.ModuleInfo != null && info.ModuleInfo.Id > 0)
            {
                info.ExtModelId = info.ModuleInfo.Id;
            }
            info.pagesCount = info.pages.Count + 1;
            var result = Dbctx.GgcmsArticles.Add(info);

            Dbctx.SaveChanges();
            //附件
            using (GgcmsDB db = new GgcmsDB())
            {
                foreach (GgcmsAttachments attach in info.attachments)
                {
                    attach.Articles_Id = info.Id;
                    attach.CreateTime  = DateTime.Now;
                    db.GgcmsAttachments.Add(attach);
                }
                db.SaveChanges();
            }
            //数据模型
            if (info.ModuleInfo != null && info.ModuleInfo.Id > 0)
            {
                foreach (var file in info.files.FindAll(x => x.fileType == 3))
                {
                    foreach (var item in info.ModuleInfo.Columns)
                    {
                        if (item.ColName == file.propertyName)
                        {
                            item.Value = UpFileClass.FileSave(file.filePath.ToString(), item.Value.ToString(), (int)file.fileType);
                        }
                    }
                }
                ExtendModule.SaveData(info.Id, info.ModuleInfo);
            }

            //分页保存
            if (info.pages.Count > 0)
            {
                foreach (var page in info.pages)
                {
                    UpFileClass.FileSave(page, page.files);
                    page.Article_Id = info.Id;
                    Dbctx.GgcmsArticlePages.Add(page);
                }
                Dbctx.SaveChanges();
            }
            ClearCache();
            return(Ok(result));
        }
Ejemplo n.º 16
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsFriendLinks info)
        {
            var result = Dbctx.GgcmsFriendLinks.Add(info);

            UpFileClass.FileSave(info, info.files);
            Dbctx.SaveChanges();
            ClearCache();
            CacheHelper.RemoveAllCache(CacheTypeNames.Keys);
            return(Ok(result));
        }
Ejemplo n.º 17
0
        public IHttpActionResult MultDelete(int[] ids)
        {
            var query = Dbctx.GgcmsCategories.Where(x => ids.Contains(x.Id));

            Dbctx.GgcmsCategories.RemoveRange(query);
            int c = Dbctx.SaveChanges();

            ClearCache();
            return(Ok(c));
        }
Ejemplo n.º 18
0
 private void adminStyle()
 {
     Dbctx.GgcmsStyles.Add(new GgcmsStyles()
     {
         StyleName = "默认风格",
         Folder    = "default",
         Descrip   = "默认风格"
     });
     Dbctx.SaveChanges();
 }
Ejemplo n.º 19
0
        public IHttpActionResult MultDelete(int[] ids)
        {
            var query = Dbctx.GgcmsFriendLinks.Where(x => ids.Contains(x.Id));

            Dbctx.GgcmsFriendLinks.RemoveRange(query);
            int c = Dbctx.SaveChanges();

            ClearCache();
            CacheHelper.RemoveAllCache(CacheTypeNames.Keys);
            return(Ok(c));
        }
Ejemplo n.º 20
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsTasks info)
        {
            info.RunTime = DateTime.Now;
            info.SetNextRuntime();
            var result = Dbctx.GgcmsTasks.Add(info);

            Dbctx.SaveChanges();
            ClearCache();
            CacheHelper.RemoveAllCache(CacheTypeNames.Tasks);
            return(Ok(result));
        }
Ejemplo n.º 21
0
        public IHttpActionResult MultDelete(int[] ids)
        {
            var user   = this.GetLoginUser();
            var idlist = ids.Where(x => x != user.Id).ToArray();
            var query  = Dbctx.GgcmsMembers.Where(x => idlist.Contains(x.Id));

            Dbctx.GgcmsMembers.RemoveRange(query);
            int c = Dbctx.SaveChanges();

            ClearCache();
            return(Ok(c));
        }
Ejemplo n.º 22
0
 private void categoriesInit()
 {
     Dbctx.GgcmsCategories.AddRange(new List <GgcmsCategories>()
     {
         new GgcmsCategories()
         {
             CategoryName = "首页",
             RedirectUrl  = "/"
         }
     });
     Dbctx.SaveChanges();
 }
Ejemplo n.º 23
0
 private void adminInit()
 {
     Dbctx.GgcmsMembers.AddRange(new List <GgcmsMembers>()
     {
         new GgcmsMembers()
         {
             UserName = "******",
             PassWord = Tools.getMd5Hash("123456"),
             JoinTime = DateTime.Now,
         }
     });
     Dbctx.SaveChanges();
 }
Ejemplo n.º 24
0
        public IHttpActionResult Delete(int id)
        {
            ExtendModule.TableDelete(id);
            GgcmsModules module = Dbctx.GgcmsModules.Where(x => x.Id == id).FirstOrDefault();

            if (module != null)
            {
                Dbctx.GgcmsModules.Remove(module);
                Dbctx.SaveChanges();
            }
            ClearCache();
            return(Ok(id));
        }
Ejemplo n.º 25
0
        // DELETE: api/GgcmsCategories/5
        public IHttpActionResult Delete(int id)
        {
            GgcmsDictionaries oldinfo = Dbctx.GgcmsDictionaries.Find(id);

            if (oldinfo == null)
            {
                return(BadRequest("信息不存在"));
            }

            Dbctx.GgcmsDictionaries.Remove(oldinfo);
            Dbctx.SaveChanges();
            ClearCache();
            return(Ok(oldinfo));
        }
Ejemplo n.º 26
0
        // PUT: api/GgcmsCategories/5
        public IHttpActionResult Edit(GgcmsPowers info)
        {
            if (Dbctx.GgcmsPowers.Where(x => x.Id == info.Id).Count() == 0)
            {
                return(BadRequest("信息不存在"));
            }
            //Dbctx.GgcmsPowers.Attach(info);
            //Dbctx.Entry(info).Property("goods_name").IsModified = true;
            var ent = Dbctx.Entry(info);

            ent.State = EntityState.Modified;
            Dbctx.SaveChanges();
            ClearCache();
            return(Ok(info));
        }
Ejemplo n.º 27
0
        public IHttpActionResult addview(int id)
        {
            var info = Dbctx.GgcmsArticles.Find(id);

            if (info != null)
            {
                info.Hits++;
                Dbctx.SaveChanges();
                return(Ok(info.Hits));
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 28
0
        public IHttpActionResult RunNow(int id)
        {
            var task = Dbctx.GgcmsTasks.Find(id);

            if (task == null)
            {
                return(BadRequest("任务不存在"));
            }
            task.RunTime   = DateTime.Now;
            task.TaskState = TaskStatus.Ready;
            int c = Dbctx.SaveChanges();

            ClearCache();
            CacheHelper.RemoveAllCache(CacheTypeNames.Tasks);
            return(Ok(c));
        }
Ejemplo n.º 29
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsModules module)
        {
            if (!ExtendModule.ColumnsCheck(module))
            {
                return(BadRequest("字段关键字重复"));
            }
            var result = Dbctx.GgcmsModules.Add(module);

            Dbctx.SaveChanges();
            result.TableName = "moduleTab_" + result.Id.ToString();
            result.ViewName  = "moduleView_" + result.Id.ToString();
            ExtendModule.TableCreate(module);
            Dbctx.SaveChanges();
            ClearCache();
            return(Ok(result));
        }
Ejemplo n.º 30
0
        // PUT: api/GgcmsCategories/5
        public IHttpActionResult Edit(GgcmsFriendLinks info)
        {
            if (Dbctx.GgcmsFriendLinks.Where(x => x.Id == info.Id).Count() == 0)
            {
                return(BadRequest("信息不存在"));
            }
            UpFileClass.FileSave(info, info.files);
            //Dbctx.GgcmsFriendLinks.Attach(info);
            //Dbctx.Entry(info).Property("goods_name").IsModified = true;
            var ent = Dbctx.Entry(info);

            ent.State = EntityState.Modified;
            Dbctx.SaveChanges();
            ClearCache();
            CacheHelper.RemoveAllCache(CacheTypeNames.Keys);
            return(Ok(info));
        }