Пример #1
0
        public int DeleteContent(int contentId)
        {
            using (TurizmWebEntities db = new TurizmWebEntities())
            {
                int result  = 0;
                var content = GetContentsById(contentId);

                if (content != null)
                {
                    var images = db.ContentImages.Where(x => x.Content_Id == content.Id).ToList();

                    if (images.Count > 0)
                    {
                        foreach (var item in images)
                        {
                            db.Entry(item).State = EntityState.Deleted;
                            db.ContentImages.Remove(item);
                            db.SaveChanges();
                        }
                    }


                    db.Entry(content).State = EntityState.Deleted;
                    db.Contents.Remove(content);
                    result = db.SaveChanges();
                }
                return(result);
            }
        }
Пример #2
0
        public int AddContent(ContentViewModel contentModel)
        {
            using (TurizmWebEntities db = new TurizmWebEntities())
            {
                using (TransactionScope scp = new TransactionScope())
                {
                    int     result  = 0;
                    Content content = new Content()
                    {
                        Title        = contentModel.Content_Title,
                        Detail       = contentModel.Content_Detail,
                        Panel        = contentModel.IsPanel,
                        IsActive     = true,
                        Price        = contentModel.Price,
                        Location     = contentModel.Location,
                        StartDate    = contentModel.StartDate,
                        FinishDate   = contentModel.FinishDate,
                        Rate         = contentModel.Rate,
                        NumberPeople = contentModel.NumberPeople,
                        Category_Id  = contentModel.Category,
                        Created_Date = DateTime.Now,
                    };
                    db.Contents.Add(content);
                    result = db.SaveChanges();

                    var imageLst = contentModel.Image;
                    if (imageLst.Count > 0)
                    {
                        foreach (var item in imageLst)
                        {
                            HttpPostedFileBase dx  = (HttpPostedFileBase)item;
                            ContentImage       cti = new ContentImage()
                            {
                                Original_Image_Path = new GlobalHelper().saveImage(dx, ""),
                                Created_Date        = DateTime.Now,
                                Content_Id          = content.Id
                            };
                            db.ContentImages.Add(cti);
                            db.SaveChanges();
                        }
                    }


                    scp.Complete();
                    return(result);
                }
            }
        }
Пример #3
0
        public int UpdateContent(Content model)
        {
            using (TurizmWebEntities db = new TurizmWebEntities())
            {
                int result  = 0;
                var content = GetContentsById(model.Id);
                if (content != null)
                {
                    content.Title        = model.Title;
                    content.Detail       = model.Detail;
                    content.IsActive     = model.IsActive;
                    content.Panel        = model.Panel;
                    content.Price        = model.Price;
                    content.Location     = model.Location;
                    content.StartDate    = model.StartDate;
                    content.FinishDate   = model.FinishDate;
                    content.Rate         = model.Rate;
                    content.NumberPeople = model.NumberPeople;
                    content.Category_Id  = model.Category_Id;

                    db.Entry(content).State = EntityState.Modified;
                    result = db.SaveChanges();
                }
                return(result);
            }
        }
Пример #4
0
 public int AddService(Service model)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result = 0;
         model.CreatedDate = DateTime.Now;
         db.Services.Add(model);
         result = db.SaveChanges();
         return(result);
     }
 }
Пример #5
0
 public int AddUser(User model)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result = 0;
         model.Created_Date = DateTime.Now;
         db.Users.Add(model);
         result = db.SaveChanges();
         return(result);
     }
 }
Пример #6
0
 public int DeleteCategory(int categoryid)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result   = 0;
         var category = GetCategoryById(categoryid);
         if (category != null)
         {
             db.Entry(category).State = EntityState.Deleted;
             db.Categories.Remove(category);
             result = db.SaveChanges();
         }
         return(result);
     }
 }
Пример #7
0
 public int DeleteSlider(int id)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result = 0;
         var slider = GetSliderById(id);
         if (slider != null)
         {
             db.Entry(slider).State = System.Data.Entity.EntityState.Deleted;
             db.Sliders.Remove(slider);
             result = db.SaveChanges();
         }
         return(result);
     }
 }
Пример #8
0
 public int DeleteService(int serviceId)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result  = 0;
         var service = GetServiceById(serviceId);
         if (service != null)
         {
             db.Entry(service).State = System.Data.Entity.EntityState.Deleted;
             db.Services.Remove(service);
             result = db.SaveChanges();
         }
         return(result);
     }
 }
Пример #9
0
 public int UpdateRole(Role model)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result = 0;
         var role   = GetRoleById(model.Id);
         if (role != null)
         {
             role.Role_Name       = model.Role_Name;
             db.Entry(role).State = System.Data.Entity.EntityState.Modified;
             result = db.SaveChanges();
         }
         return(result);
     }
 }
Пример #10
0
 public int DeleteRole(int id)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result = 0;
         var role   = GetRoleById(id);
         if (role != null)
         {
             db.Entry(role).State = System.Data.Entity.EntityState.Deleted;
             db.Roles.Remove(role);
             result = db.SaveChanges();
         }
         return(result);
     }
 }
Пример #11
0
 public int AddRole(RoleModel model)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         Role rl = new Role()
         {
             Role_Name    = model.RolName,
             Created_Date = model.CreatedDate
         };
         int sonuc = 0;
         db.Roles.Add(rl);
         sonuc = db.SaveChanges();
         return(sonuc);
     }
 }
Пример #12
0
 public bool DeleteContentImage(int id)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         bool result = false;
         var  image  = GetImageById(id);
         if (image != null)
         {
             db.Entry(image).State = EntityState.Deleted;
             db.ContentImages.Remove(image);
             int resultx = db.SaveChanges();
             result = resultx == 1 ? true : false;
         }
         return(result);
     }
 }
Пример #13
0
 public int UpdateSlider(Slider model)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result = 0;
         var slider = GetSliderById(model.Id);
         if (slider != null)
         {
             slider.Title           = model.Title;
             slider.Description     = model.Description;
             db.Entry(slider).State = System.Data.Entity.EntityState.Modified;
             result = db.SaveChanges();
         }
         return(result);
     }
 }
Пример #14
0
 public int UpdateCategory(Category model)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result    = 0;
         var category_ = GetCategoryById(model.Id);
         if (category_ != null)
         {
             category_.Name            = model.Name;
             category_.Description     = model.Description;
             db.Entry(category_).State = EntityState.Modified;
             result = db.SaveChanges();
         }
         return(result);
     }
 }
Пример #15
0
        public int UpdateService(Service model)
        {
            using (TurizmWebEntities db = new TurizmWebEntities())
            {
                int result  = 0;
                var service = GetServiceById(model.Id);
                if (service != null)
                {
                    service.Title  = model.Title;
                    service.Detail = model.Detail;

                    db.Entry(service).State = System.Data.Entity.EntityState.Modified;
                    result = db.SaveChanges();
                }
                return(result);
            }
        }
Пример #16
0
        public int UpdateUser(User model)
        {
            using (TurizmWebEntities db = new TurizmWebEntities())
            {
                int result = 0;
                var user   = GetUserById(model.Id);
                if (user != null)
                {
                    user.First_Name = model.First_Name;
                    user.Last_Name  = model.Last_Name;
                    user.Phone      = model.Phone;
                    user.Email      = model.Email;
                    user.Password   = model.Password;
                    user.Role_Id    = model.Role_Id;

                    db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    result = db.SaveChanges();
                }
                return(result);
            }
        }
Пример #17
0
 public int UpdateStatus(int id)
 {
     using (TurizmWebEntities db = new TurizmWebEntities())
     {
         int result  = 0;
         var content = GetContentsById(id);
         if (content != null)
         {
             if (content.IsActive == true)
             {
                 content.IsActive = false;
             }
             else
             {
                 content.IsActive = true;
             }
             db.Entry(content).State = EntityState.Modified;
             result = db.SaveChanges();
         }
         return(result);
     }
 }
Пример #18
0
        public int UpdateContentImage(ContentImage model, HttpPostedFileBase newimage)
        {
            using (TurizmWebEntities db = new TurizmWebEntities())
            {
                int result = 0;
                //object modelImage = model.Original_Image_Path;
                //HttpPostedFileBase img = modelImage as HttpPostedFileBase;
                if (newimage != null)
                {
                    string newImagePath = new GlobalHelper().saveImage(newimage, model.Original_Image_Path);

                    var image = GetImageById(model.Id);
                    if (image != null)
                    {
                        image.Original_Image_Path = newImagePath;

                        db.Entry(image).State = EntityState.Modified;
                        result = db.SaveChanges();
                    }
                }
                return(result);
            }
        }