public bool EditArticle(NewArticleModel model, HttpPostedFileBase articleTitlePhoto, HttpPostedFileBase articlePhoto) { var repo = DependencyResolver.Current.GetService <IRepository>(); var auth = DependencyResolver.Current.GetService <IAuthProvider>(); var userGuid = auth.UserGuid; if (articlePhoto != null) { FileProvider.DeleteFile(model.Photo); model.Photo = FileProvider.SaveArticlePhoto(articlePhoto); } if (articleTitlePhoto != null) { FileProvider.DeleteFile(model.TitlePhoto); model.TitlePhoto = FileProvider.SaveArticleTitlePhoto(articleTitlePhoto); } if (string.IsNullOrEmpty(model.Title) && !string.IsNullOrEmpty(model.TitleEn)) { model.Title = model.TitleEn; } if (string.IsNullOrEmpty(model.Description) && !string.IsNullOrEmpty(model.DescriptionEn)) { model.Description = model.DescriptionEn; } if (string.IsNullOrEmpty(model.Text) && !string.IsNullOrEmpty(model.TextEn)) { model.Text = model.TextEn; } if (string.IsNullOrEmpty(model.SourcePhoto) && !string.IsNullOrEmpty(model.SourcePhotoEn)) { model.SourcePhoto = model.SourcePhotoEn; } if (string.IsNullOrEmpty(model.SourceUrl) && !string.IsNullOrEmpty(model.SourceUrlEn)) { model.SourceUrl = model.SourceUrlEn; } repo.EditArticle(model, userGuid); return(true); }
public bool EditCategory(category model, HttpPostedFileBase categoryIcon, HttpPostedFileBase categoryPin) { var repo = DependencyResolver.Current.GetService <IRepository>(); var prevCategory = repo.GetCategory(model.Id); var previousIcon = prevCategory.Icon; var previousPin = prevCategory.Pin; if (categoryIcon != null) { FileProvider.DeleteFile(previousIcon); var filePath = FileProvider.SaveCategoryIcon(categoryIcon); model.Icon = filePath; } else { model.Icon = previousIcon; } if (categoryPin != null) { FileProvider.DeleteFile(previousPin); var filePath = FileProvider.SaveCategoryIcon(categoryPin, 50, 50); model.Pin = filePath; } else { model.Pin = previousPin; } model.Color = model.Color.Replace("#", ""); if (string.IsNullOrEmpty(model.Name) && !string.IsNullOrEmpty(model.EnName)) { model.Name = model.EnName; } repo.EditCategory(model); return(true); }
public bool EditMarker(NewMarkerModel model, string openTimesString, string closeTimesString, HttpPostedFileBase markerPhoto, HttpPostedFileBase markerLogo, IEnumerable <HttpPostedFileBase> markerPhotos, string removePhotosString) { var repo = DependencyResolver.Current.GetService <IRepository>(); var auth = DependencyResolver.Current.GetService <IAuthProvider>(); if (repo.GetCities().All(tc => tc.Id != model.CityId)) { model.CityId = 0; } if (string.IsNullOrEmpty(model.Street) || model.Street == "Unnamed Road") { model.Street = "Улица не определена"; } if (string.IsNullOrEmpty(model.House)) { model.House = "Нет"; } var openTimes = JsonConvert.DeserializeObject <List <WorkTimeDay> >(openTimesString); var closeTimes = JsonConvert.DeserializeObject <List <WorkTimeDay> >(closeTimesString); var removePhotos = JsonConvert.DeserializeObject <List <RemovePhoto> >(removePhotosString); var removePhotoIds = removePhotos.Select(p => p.id); var userGuid = auth.UserGuid; if (markerPhoto != null) { FileProvider.DeleteFile(model.Photo); var filePath = FileProvider.SaveMarkerPhoto(markerPhoto); model.Photo = filePath; } if (markerLogo != null) { FileProvider.DeleteFile(model.Logo); var filePath = FileProvider.SaveMarkerLogo(markerLogo); model.Logo = filePath; } if (markerPhotos != null && markerPhotos.Any()) { model.marker_photos = new List <marker_photos>(); foreach (var photo in markerPhotos) { var filePath = FileProvider.SaveMarkerPhoto(photo); model.marker_photos.Add(new marker_photos { Photo = filePath }); } } if (removePhotos != null && removePhotos.Any()) { foreach (var photo in removePhotos) { FileProvider.DeleteFile(photo.photo); } } if (string.IsNullOrEmpty(model.Name) && !string.IsNullOrEmpty(model.NameEn)) { model.Name = model.NameEn; } if (string.IsNullOrEmpty(model.Introduction) && !string.IsNullOrEmpty(model.IntroductionEn)) { model.Introduction = model.IntroductionEn; } if (string.IsNullOrEmpty(model.Description) && !string.IsNullOrEmpty(model.DescriptionEn)) { model.Description = model.DescriptionEn; } repo.EditMarker(model, openTimes, closeTimes, removePhotoIds?.ToList(), userGuid); return(true); }
public bool AddNewMarker(NewMarkerModel model, string openTimesString, string closeTimesString, HttpPostedFileBase markerPhoto, HttpPostedFileBase markerLogo, List <HttpPostedFileBase> markerPhotos, float lat, float lng) { if (Math.Abs(model.Lat) <= 0) { model.Lat = lat; } if (Math.Abs(model.Lng) <= 0) { model.Lng = lng; } var openTimes = JsonConvert.DeserializeObject <List <WorkTimeDay> >(openTimesString); var closeTimes = JsonConvert.DeserializeObject <List <WorkTimeDay> >(closeTimesString); var repo = DependencyResolver.Current.GetService <IRepository>(); var auth = DependencyResolver.Current.GetService <IAuthProvider>(); var userGuid = auth.UserGuid; if (markerPhoto != null) { FileProvider.DeleteFile(model.Photo); var filePath = FileProvider.SaveMarkerPhoto(markerPhoto); model.Photo = filePath; } if (markerLogo != null) { FileProvider.DeleteFile(model.Logo); var filePath = FileProvider.SaveMarkerLogo(markerLogo); model.Logo = filePath; } if (markerPhotos != null && markerPhotos.Any()) { model.marker_photos = new List <marker_photos>(); foreach (var photo in markerPhotos) { var filePath = FileProvider.SaveMarkerPhoto(photo); model.marker_photos.Add(new marker_photos { Photo = filePath }); } } if (string.IsNullOrEmpty(model.Name) && !string.IsNullOrEmpty(model.NameEn)) { model.Name = model.NameEn; } if (string.IsNullOrEmpty(model.Introduction) && !string.IsNullOrEmpty(model.IntroductionEn)) { model.Introduction = model.IntroductionEn; } if (string.IsNullOrEmpty(model.Description) && !string.IsNullOrEmpty(model.DescriptionEn)) { model.Description = model.DescriptionEn; } var tempNewMarkerId = repo.AddMarker(model, openTimes, closeTimes, userGuid); return(true); }