コード例 #1
0
        public void Edit(string existingTag, string newTag)
        {
            using (var db = new CmsContext())
            {
                var posts = db.Posts.Where(post => post.CombinedTags.Contains(existingTag))
                    .ToList();

                posts = posts.Where(post => 
                    post.Tags.Contains(existingTag, StringComparer.CurrentCultureIgnoreCase))
                    .ToList();

                if (!posts.Any())
                {
                    throw new KeyNotFoundException("The tag " + existingTag + " does not exist.");
                }

                foreach (var post in posts)
                {
                    post.Tags.Remove(existingTag);
                    post.Tags.Add(newTag);
                }

                db.SaveChanges();
            }
        }
コード例 #2
0
        public void Delete(string id)
        {
            using (var db = new CmsContext())
            {
                var post = db.Posts.SingleOrDefault(p => p.Id == id);

                if (post == null)
                {
                    throw new KeyNotFoundException("The post with the id of " + id + " does not exist");
                }

                db.Posts.Remove(post);
                db.SaveChanges();
            }
        }
コード例 #3
0
        public void Create(Post model)
        {
            using (var db = new CmsContext())
            {
                var post = db.Posts.SingleOrDefault(p => p.Id == model.Id);

                if (post != null)
                {
                    throw new ArgumentException("A post with the id of " + model.Id + " already exists.");
                }

                db.Posts.Add(model);
                db.SaveChanges();
            }
        }
コード例 #4
0
        public void ArticleTopCategorySave(int ArticleId)
        {
            var ArticleCategoryArticle_Item = CmsContext.ArticleCategoryArticle.FirstOrDefault(p => p.ArticleId == ArticleId);
            int ArticleCategoryId           = ArticleCategoryArticle_Item.ArticleCategoryId;

            //var ArticleTop_Items = CmsContext.ArticleTop.Where(p => p.ArticleCategoryId == ArticleCategoryId);
            //CmsContext.ArticleTop.RemoveRange(ArticleTop_Items);

            ArticleTop ArticleTop_Item = new ArticleTop();

            ArticleTop_Item.ArticleCategoryId = ArticleCategoryId;
            ArticleTop_Item.ArticleId         = ArticleId;
            CmsContext.ArticleTop.Add(ArticleTop_Item);

            CmsContext.SaveChanges();
        }
コード例 #5
0
        public void ProductTopCategorySave(int ProductId)
        {
            var ProductCategoryProduct_Item = CmsContext.ProductCategoryProduct.FirstOrDefault(p => p.ProductId == ProductId);
            int ProductCategoryId           = ProductCategoryProduct_Item.ProductCategoryId;

            //var ProductTop_Items = CmsContext.ProductTop.Where(p => p.ProductCategoryId == ProductCategoryId);
            //CmsContext.ProductTop.RemoveRange(ProductTop_Items);

            ProductTop ProductTop_Item = new ProductTop();

            ProductTop_Item.ProductCategoryId = ProductCategoryId;
            ProductTop_Item.ProductId         = ProductId;
            CmsContext.ProductTop.Add(ProductTop_Item);

            CmsContext.SaveChanges();
        }
コード例 #6
0
        public void Put([FromServices] CmsContext _db, int id, [FromForm] FormularioDeNoticias formularioDeNoticias)
        {
            Noticia noticia = _db.Noticias.Find(id);

            if (noticia == null)
            {
                NotFound();
            }

            noticia.Titulo         = formularioDeNoticias.Titulo;
            noticia.Conteudo       = formularioDeNoticias.Conteudo;
            noticia.DataPublicacao = formularioDeNoticias.DataPublicacao;

            _db.Noticias.Update(noticia);
            _db.SaveChanges();
        }
コード例 #7
0
        public async Task ArticleSetArticleCategory(int ArticleId, int ArticleCategoryId)
        {
            var item = await CmsContext.ArticleCategoryArticle.FirstOrDefaultAsync(p => p.ArticleId == ArticleId && p.ArticleCategoryId == ArticleCategoryId);

            if (item != null) // Update
            {
                item.ArticleCategoryId = ArticleCategoryId;
                CmsContext.SaveChanges();
            }
            else
            {
                var addItem = new ArticleCategoryArticle();
                addItem.ArticleId         = ArticleId;
                addItem.ArticleCategoryId = ArticleCategoryId;
                CmsContext.ArticleCategoryArticle.Add(addItem);
                await CmsContext.SaveChangesAsync();
            }
        }
コード例 #8
0
 public override void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     using (CmsContext Context = new CmsContext())
     {
         List <WebUser> Users = Context.Set <WebUser>().Where(Usr => usernames.Contains(Usr.AdName)).ToList();
         List <WebRole> Roles = Context.Set <WebRole>().Where(Rl => roleNames.Contains(Rl.RoleName)).ToList();
         foreach (WebUser user in Users)
         {
             foreach (WebRole role in Roles)
             {
                 if (!user.Roles.Contains(role))
                 {
                     user.Roles.Add(role);
                 }
             }
         }
         Context.SaveChanges();
     }
 }
コード例 #9
0
ファイル: SeedData.cs プロジェクト: Kyoungtaek/CMS
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new CmsContext(serviceProvider.GetRequiredService <DbContextOptions <CmsContext> >()))
            {
                if (context.Pages.Any())
                {
                    return;
                }

                context.Pages.AddRange(
                    new Page
                {
                    Title   = "Home",
                    Slug    = "home",
                    Content = "home page",
                    Sorting = 0
                },
                    new Page
                {
                    Title   = "About Us",
                    Slug    = "about-us",
                    Content = "about us page",
                    Sorting = 100
                },
                    new Page
                {
                    Title   = "Services",
                    Slug    = "services",
                    Content = "services page",
                    Sorting = 100
                },
                    new Page
                {
                    Title   = "Contact",
                    Slug    = "contact",
                    Content = "contact page",
                    Sorting = 100
                }
                    );
                context.SaveChanges();
            }
        }
コード例 #10
0
 public override void CreateRole(string roleName)
 {
     if (!string.IsNullOrEmpty(roleName))
     {
         using (CmsContext Context = new CmsContext())
         {
             WebRole Role = null;
             Role = Context.Set <WebRole>().FirstOrDefault(Rl => Rl.RoleName == roleName);
             if (Role == null)
             {
                 WebRole NewRole = new WebRole
                 {
                     RoleName = roleName
                 };
                 Context.Set <WebRole>().Add(NewRole);
                 Context.SaveChanges();
             }
         }
     }
 }
コード例 #11
0
        public bool UpdateServiceTemplate(ServiceTemplate serviceTemplate)
        {
            var existingTemplate = db.ServiceTemplates.FirstOrDefault(p => p.Id == serviceTemplate.Id);

            if (existingTemplate != null)
            {
                existingTemplate.Name       = serviceTemplate.Name;
                existingTemplate.UseTasks   = serviceTemplate.UseTasks;
                existingTemplate.Url        = serviceTemplate.Url;
                existingTemplate.JsonFields = serviceTemplate.JsonFields;
            }
            else
            {
                db.ServiceTemplates.Add(serviceTemplate);
            }

            db.SaveChanges();

            return(true);
        }
コード例 #12
0
        public void ArticleTopParentCategorySave(int ArticleId)
        {
            var ArticleCategoryArticle_Item = CmsContext.ArticleCategoryArticle.FirstOrDefault(p => p.ArticleId == ArticleId);
            int ArticleCategoryId           = ArticleCategoryArticle_Item.ArticleCategoryId;

            var ArticleCategory_Item = CmsContext.ArticleCategory.FirstOrDefault(p => p.Id == ArticleCategoryId);

            if (ArticleCategory_Item.ParentId != null)
            {
                int ArticleCategoryParentId = ArticleCategory_Item.ParentId.Value;
                //var ArticleTop_Items = CmsContext.ArticleTop.Where(p => p.ArticleCategoryId == ArticleCategoryParentId);
                //CmsContext.ArticleTop.RemoveRange(ArticleTop_Items);

                ArticleTop ArticleTop_Item = new ArticleTop();
                ArticleTop_Item.ArticleCategoryId = ArticleCategoryParentId;
                ArticleTop_Item.ArticleId         = ArticleId;
                CmsContext.ArticleTop.Add(ArticleTop_Item);

                CmsContext.SaveChanges();
            }
        }
コード例 #13
0
        public void Edit(string id, Models.Post updatedItem)
        {
            using (var db = new CmsContext())
            {
                var post = db.Posts.SingleOrDefault(p => p.Id == id);

                if (post == null)
                {
                    throw new KeyNotFoundException("A post with the id of " 
                        + id + " does not exist in the data store.");
                }

                post.Id = updatedItem.Id;
                post.Title = updatedItem.Title;
                post.Content = updatedItem.Content;
                post.Published = updatedItem.Published;
                post.Tags = updatedItem.Tags;

                db.SaveChanges();
            }
        }
コード例 #14
0
ファイル: ContenidoLogic.cs プロジェクト: hilda91/Cms
        public ResponseModel Eliminar(int id)
        {
            var rm = new ResponseModel();

            try
            {
                using (var ctx = new CmsContext())
                {
                    contenido.idContenido = id;
                    ctx.Entry(this).State = EntityState.Deleted;

                    ctx.SaveChanges();
                    rm.SetResponse(true);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(rm);
        }
コード例 #15
0
        public void Edit(string id, Post updateModel)
        {
            using (var db = new CmsContext())
            {
                var editablePost = db.Posts.SingleOrDefault(post => post.Id == id);

                // TODO oma metodi IsNull
                if (editablePost.IsNull())
                {
                    throw new KeyNotFoundException("A post with the id of "
                        + id + "doe not exists in the data store");
                }

                editablePost.Id = updateModel.Id;
                editablePost.Title = updateModel.Title;
                editablePost.Content = updateModel.Content;
                editablePost.Published = updateModel.Published;
                editablePost.Tags = updateModel.Tags;

                db.SaveChanges();
            }
        }
コード例 #16
0
ファイル: WebSecurityHelpers.cs プロジェクト: pir8aye/FRA-CMS
        public static void UpdateOrCreateSubmitTime(string ip)
        {
            using (CmsContext db = new CmsContext())
            {
                var now  = DateTime.Now;
                var last = db.Set <FormSubmitRequest>().SingleOrDefault(e => e.ClientIP == ip);
                if (last != null)
                {
                    last.LastSubmit = now;
                }
                else
                {
                    last = new FormSubmitRequest
                    {
                        ClientIP   = ip,
                        LastSubmit = now
                    };

                    db.Set <FormSubmitRequest>().Add(last);
                    db.SaveChanges();
                }
            }
        }
コード例 #17
0
 public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
 {
     using (CmsContext Context = new CmsContext())
     {
         foreach (String username in usernames)
         {
             String  us   = username;
             WebUser user = Context.Set <WebUser>().FirstOrDefault(U => U.AdName == us);
             if (user != null)
             {
                 foreach (String roleName in roleNames)
                 {
                     String  rl   = roleName;
                     WebRole role = user.Roles.FirstOrDefault(R => R.RoleName == rl);
                     if (role != null)
                     {
                         user.Roles.Remove(role);
                     }
                 }
             }
         }
         Context.SaveChanges();
     }
 }
コード例 #18
0
        public void ArticleSaveRelatedArticle(int IsAdd, int ArticleRelateId, int ArticleID)
        {
            var items = CmsContext.ArticleRelationArticle.FirstOrDefault(p => p.ArticleId == ArticleID && p.ArticleRelationId == ArticleRelateId);

            if (IsAdd == 1)
            {
                if (items == null)
                {
                    ArticleRelationArticle art = new ArticleRelationArticle();
                    art.ArticleRelationId = ArticleRelateId;
                    art.ArticleId         = ArticleID;
                    CmsContext.ArticleRelationArticle.Add(art);
                    CmsContext.SaveChanges();
                }
            }
            else
            {
                if (items != null)
                {
                    CmsContext.ArticleRelationArticle.Remove(items);
                    CmsContext.SaveChanges();
                }
            }
        }
コード例 #19
0
        public IHttpActionResult PutPropertyTaskListType(int id, PropertyTaskListType propertyTaskListType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != propertyTaskListType.Id)
            {
                return(BadRequest());
            }

            var originalPropertyTaskListType = db.PropertyTaskListTypes
                                               .Where(t => t.Id == propertyTaskListType.Id)
                                               .Include(t => t.PropertyTaskHeaders)
                                               .SingleOrDefault();

            if (originalPropertyTaskListType == null)
            {
                return(NotFound());
            }

            var originalEntry = db.Entry(originalPropertyTaskListType);

            originalEntry.CurrentValues.SetValues(propertyTaskListType);

            foreach (var header in propertyTaskListType.PropertyTaskHeaders)
            {
                var originalHeader = originalPropertyTaskListType.PropertyTaskHeaders
                                     .SingleOrDefault(h => h.Id == header.Id && h.Id != 0);

                if (originalHeader != null)
                {
                    if (string.IsNullOrWhiteSpace(header.Name))
                    {
                        db.PropertyTaskDetails.Where(d => d.PropertyTaskHeaderId == originalHeader.Id)
                        .ToList()
                        .ForEach(d => db.PropertyTaskDetails.Remove(d));
                        db.PropertyTaskHeaders.Remove(originalHeader);
                    }
                    else
                    {
                        var headerEntry = db.Entry(originalHeader);
                        headerEntry.CurrentValues.SetValues(header);
                    }
                }
                else
                {
                    header.Id = 0;
                    originalPropertyTaskListType.PropertyTaskHeaders.Add(header);
                }
            }

            foreach (var originalHeader in originalPropertyTaskListType.PropertyTaskHeaders.Where(h => h.Id != 0).Where(originalHeader => propertyTaskListType.PropertyTaskHeaders.All(h => h.Id != originalHeader.Id)).ToList())
            {
                db.PropertyTaskDetails.Where(d => d.PropertyTaskHeaderId == originalHeader.Id)
                .ToList()
                .ForEach(d => db.PropertyTaskDetails.Remove(d));
                db.PropertyTaskHeaders.Remove(originalHeader);
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PropertyTaskListTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #20
0
 public void Add(Category entity)
 {
     context.Category.Add(entity);
     context.SaveChanges();
 }
コード例 #21
0
 public void Save()
 {
     _cmsContext.SaveChanges();
 }
コード例 #22
0
 public void Add(Contact entity)
 {
     context.Contact.Add(entity);
     context.SaveChanges();
 }
コード例 #23
0
ファイル: EFReferenceDal.cs プロジェクト: beratzmen/Corp_Cms
 public void Add(Reference entity)
 {
     context.Reference.Add(entity);
     context.SaveChanges();
 }
コード例 #24
0
 public void Add(Pages entity)
 {
     context.Pages.Add(entity);
     context.SaveChanges();
 }
コード例 #25
0
 public void Alterar(params TEntity[] obj)
 {
     DbSet.UpdateRange(obj);
     context.SaveChanges();
 }
コード例 #26
0
ファイル: EFCompanyDal.cs プロジェクト: beratzmen/Corp_Cms
 public void Add(Company entity)
 {
     context.Company.Add(entity);
     context.SaveChanges();
 }
コード例 #27
0
 public void Add(Product entity)
 {
     context.Product.Add(entity);
     context.SaveChanges();
 }
コード例 #28
0
ファイル: EFSocialIconDal.cs プロジェクト: beratzmen/Corp_Cms
 public void Add(SocialIcon entity)
 {
     context.SocialIcon.Add(entity);
     context.SaveChanges();
 }
コード例 #29
0
ファイル: EFBulletinDal.cs プロジェクト: beratzmen/Corp_Cms
 public void Add(Bulletin entity)
 {
     context.Bulletin.Add(entity);
     context.SaveChanges();
 }
コード例 #30
0
ファイル: EFNewsDal.cs プロジェクト: beratzmen/Corp_Cms
 public void Add(News entity)
 {
     context.News.Add(entity);
     context.SaveChanges();
 }
コード例 #31
0
        public IHttpActionResult GetServiceTicket(int id, DateTime date)
        {
            var eventTaskList = db.EventTaskLists.Include("EventTaskTimes").FirstOrDefault(e => e.Id == id);

            if (eventTaskList == null || !eventTaskList.ServiceTemplateId.HasValue)
            {
                return(NotFound());
            }

            var serviceTemplate = db.ServiceTemplates.FirstOrDefault(s => s.Id == eventTaskList.ServiceTemplateId);
            var property        = db.Properties.FirstOrDefault(p => p.Id == eventTaskList.PropertyId);

            if (serviceTemplate == null || property == null)
            {
                return(NotFound());
            }

            var serviceTicket = db.ServiceTickets.FirstOrDefault(s => s.EventTaskListId == id && s.EventDate == date);

            if (serviceTicket == null)
            {
                serviceTicket = new ServiceTicket();
                serviceTicket.EventTaskListId = id;
                serviceTicket.EventDate       = date;
                var eventTaskTime = eventTaskList.EventTaskTimes.FirstOrDefault(e => e.EventDate.Subtract(serviceTicket.EventDate.Value) == TimeSpan.Zero);
                if (eventTaskTime != null)
                {
                    serviceTicket.VisitFromTime = eventTaskTime.StartTime?.AddHours(4) ?? DateTime.Today.AddHours(8);
                    serviceTicket.VisitToTime   = eventTaskTime.EndTime?.AddHours(4) ?? DateTime.Today.AddHours(10);
                }
                else
                {
                    serviceTicket.VisitFromTime = DateTime.Today.AddHours(8);
                    serviceTicket.VisitToTime   = DateTime.Today.AddHours(10);
                }
                serviceTicket.ServiceTemplateId = serviceTemplate.Id;
                // if (serviceTemplate.UseTasks)
                // {
                var tasks = from t in db.PropertyTasks
                            where t.EventTaskListId == eventTaskList.Id
                            select new TaskInfo()
                {
                    Description = t.Description,
                    Location    = t.Location,
                    Completed   = false,
                    Comment     = string.Empty
                };

                //   serviceTicket.JsonFields = "{\"Tasks\":" + JsonConvert.SerializeObject(tasks.ToList()) + "}";

                // }
                // else
                // {

                JObject json       = JObject.Parse(serviceTemplate.JsonFields);
                JArray  tasksArray = (JArray)json["Tasks"];
                if (!tasksArray.HasValues)
                {
                    foreach (var task in tasks)
                    {
                        tasksArray.Add(JObject.FromObject(task));
                    }
                }

                serviceTicket.JsonFields = JsonConvert.SerializeObject(json);

                //  }
                serviceTicket.ReferenceNumber = property.PropertyRefNumber;
                db.ServiceTickets.Add(serviceTicket);
                db.SaveChanges();
            }

            var serviceMembers = from e in db.Employees
                                 join c in db.CrewMembers on

                                 new
            {
                EmployeeId = e.Id,
                eventTaskList.CrewId
            } equals new
            {
                c.EmployeeId,
                c.CrewId
            }
            into cm
            from c in cm.DefaultIfEmpty()
            orderby e.FirstName, e.LastName
                select new ServiceMemberViewModel()
            {
                EmployeeId   = e.Id,
                FirstName    = e.FirstName,
                LastName     = e.LastName,
                IsCrewMember = c != null,
                Selected     = db.ServiceMembers.Any(s => s.EmployeeId == e.Id && s.ServiceTicketId == serviceTicket.Id)
            };

            var ticket = serviceTicket.MapTo <ServiceTicketViewModel>();

            ticket.TemplateName     = serviceTemplate.Name;
            ticket.TemplateUseTasks = serviceTemplate.UseTasks;
            ticket.TemplateUrl      = serviceTemplate.Url;
            ticket.PropertyName     = property.Name;
            ticket.Address1         = property.Address1;
            ticket.Address2         = property.Address2;
            ticket.City             = property.City != null ? property.City.Name : "";
            ticket.State            = property.State;
            ticket.Zip              = property.Zip;
            ticket.Members          = serviceMembers.ToList();
            ticket.ShowAllEmployees = serviceMembers.Any(s => s.Selected && !s.IsCrewMember);
            if (property.Customer != null)
            {
                ticket.AccessDetails = property.Customer.AccessDetails;
                ticket.CustomerName  = property.Customer.FirstName + " " + property.Customer.LastName;
            }
            return(Ok(ticket));
        }
コード例 #32
0
 public void Add(Role entity)
 {
     context.Role.Add(entity);
     context.SaveChanges();
 }
コード例 #33
0
ファイル: EFJobUserDal.cs プロジェクト: beratzmen/Corp_Cms
 public void Add(JobUser entity)
 {
     context.JobUser.Add(entity);
     context.SaveChanges();
 }
コード例 #34
0
 public void Add(Slider entity)
 {
     context.Slider.Add(entity);
     context.SaveChanges();
 }