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); } } }
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); } }