コード例 #1
0
 public ActionResult Edit([Bind(Include = "id_Collection,Nom")] Collections collections)
 {
     if (ModelState.IsValid)
     {
         db.Entry(collections).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(collections));
 }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "id_TypeAuteur,Nom")] Type_Auteur type_Auteur)
 {
     if (ModelState.IsValid)
     {
         db.Entry(type_Auteur).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(type_Auteur));
 }
コード例 #3
0
        public async Task SaveLastReadAsync(string code, int userId, int?lastPageNumber)
        {
            try
            {
                code = code?.ToLower() ?? "";
                Document document = await biblioEntities.Documents.FirstOrDefaultAsync
                                    (
                    x =>
                    x.Code.ToLower() == code
                                    );

                if (document != null)
                {
                    UserDocument currentUserDocument = GetLastUserDocument(document.Id, userId);
                    var          newUserDocument     = new UserDocument
                                                       (
                        currentUserDocument?.Id ?? 0,
                        userId,
                        document.Id,
                        lastPageNumber ?? (currentUserDocument?.LastPageNumber ?? 1),
                        currentUserDocument?.ReadDate ?? DateTime.UtcNow
                                                       );
                    if (currentUserDocument == null)
                    {
                        biblioEntities.UserDocuments.Add(newUserDocument);
                    }
                    else
                    {
                        biblioEntities.Entry(currentUserDocument).CurrentValues.SetValues(newUserDocument);
                    }
                    await biblioEntities.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
ファイル: AuteursController.cs プロジェクト: adridn/biblio
 public ActionResult Edit(CreateAuteurViewModel typeAuteur)
 {
     if (ModelState.IsValid)
     {
         Auteur auteur = new Auteur();
         auteur.id_Auteur       = typeAuteur.id_Auteur;
         auteur.id_TypeAuteur   = typeAuteur.id_TypeAuteur;
         auteur.Nom             = typeAuteur.Nom;
         db.Entry(auteur).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(typeAuteur));
 }
コード例 #5
0
        public ActionResult Edit(LivreViewModel lvm)
        {
            if (ModelState.IsValid)
            {
                Livre livre = new Livre();
                livre.id_Livre       = lvm.id_Livre;
                livre.id_Auteur      = lvm.id_Auteur;
                livre.id_Collection  = lvm.id_Collection;
                livre.id_Dessinateur = lvm.id_Dessinateur;
                livre.Nom            = lvm.Nom;

                db.Entry(livre).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(lvm));
        }
コード例 #6
0
        public async Task <CategoryModel> SetAsync(CategoryModel categoryModel,
                                                   string mediaFolderPath, string prefixCategoryImageName)
        {
            string newImageName          = null;
            var    mediaAbsoluteBasePath = Path.Combine(env.WebRootPath, mediaFolderPath?.Replace("~/", string.Empty));

            try
            {
                string oldImageName = null;
                if (categoryModel == null)
                {
                    throw new ArgumentNullException("categoryModel");
                }

                bool deleteCurrentImage = false;

                var currentCategory = await biblioEntities.Categories.FindAsync(categoryModel.Id);

                if (currentCategory == null)
                {
                    throw new KeyNotFoundException("Category");
                }

                oldImageName = currentCategory.Image;

                if (Tools.OssFile.HasImage(categoryModel.ImageUploaded))
                {
                    newImageName       = Tools.OssFile.SaveImage(categoryModel.ImageUploaded, 300, 300, 100 * 1024, 200 * 1024, prefixCategoryImageName, mediaAbsoluteBasePath);;
                    deleteCurrentImage = true;
                }
                else if (!string.IsNullOrEmpty(currentCategory.Image) && categoryModel.DeleteImage)
                {
                    deleteCurrentImage = true;
                }
                else
                {
                    newImageName = currentCategory.Image;
                }
                Category newCategory = new Category
                                       (
                    categoryModel.Id,
                    categoryModel.Name,
                    categoryModel.Description,
                    categoryModel.CategoryParentId,
                    null,
                    newImageName,
                    (short)categoryModel.Status
                                       );

                biblioEntities.Entry(currentCategory).CurrentValues.SetValues(newCategory);
                await biblioEntities.SaveChangesAsync();

                if (deleteCurrentImage)
                {
                    Tools.OssFile.DeleteFile(oldImageName, mediaAbsoluteBasePath);
                }

                return(new CategoryModel(newCategory, this, mediaFolderPath));
            }
            catch (Exception ex)
            {
                if (Tools.OssFile.HasImage(categoryModel.ImageUploaded) && !string.IsNullOrEmpty(newImageName))
                {
                    Tools.OssFile.DeleteFile(newImageName, mediaAbsoluteBasePath);
                }
                throw ex;
            }
        }
コード例 #7
0
        public async Task <ProfileModel> EditProfilAsync(ProfileModel profileModel,
                                                         HttpRequest request, string mediaFolderPath, string prefixPhotoProfileName)
        {
            string newImageName          = null;
            var    mediaAbsoluteBasePath = Path.Combine(env.WebRootPath, mediaFolderPath?.Replace("~/", string.Empty));

            try
            {
                string oldImageName = null;
                var    currentUser  = await biblioEntities.Users.SingleOrDefaultAsync
                                      (
                    x => x.Account.Equals(request.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value, StringComparison.OrdinalIgnoreCase)
                                      );

                if (currentUser == null)
                {
                    throw new KeyNotFoundException("Profile");
                }

                bool deleteCurrentImage = false;
                oldImageName = currentUser.Image;
                if (Tools.OssFile.HasImage(profileModel.ImageUploaded))
                {
                    newImageName       = Tools.OssFile.SaveImage(profileModel.ImageUploaded, 300, 300, 100 * 1024, 200 * 1024, prefixPhotoProfileName, mediaAbsoluteBasePath);;
                    deleteCurrentImage = true;
                }
                else if (!string.IsNullOrEmpty(currentUser.Image) && profileModel.DeleteImage)
                {
                    deleteCurrentImage = true;
                }
                else
                {
                    newImageName = currentUser.Image;
                }

                var  newPassword = GetPassword(currentUser.Password, profileModel.Password);
                User newUser     = new User
                                   (
                    currentUser.Id,
                    currentUser.Account,
                    newPassword,
                    currentUser.FullName,
                    currentUser.Role,
                    newImageName,
                    currentUser.Status
                                   );

                biblioEntities.Entry(currentUser).CurrentValues.SetValues(newUser);
                await biblioEntities.SaveChangesAsync();

                if (deleteCurrentImage)
                {
                    Tools.OssFile.DeleteFile(oldImageName, mediaAbsoluteBasePath);
                }

                profileModel = new ProfileModel(newUser, mediaFolderPath);
                return(profileModel);
            }
            catch (Exception ex)
            {
                if (Tools.OssFile.HasImage(profileModel.ImageUploaded) && !string.IsNullOrEmpty(newImageName))
                {
                    Tools.OssFile.DeleteFile(newImageName, mediaAbsoluteBasePath);
                }
                throw ex;
            }
        }
コード例 #8
0
        public async Task <SuggestionModel> SetAsync(SuggestionModel suggestionModel,
                                                     string mediaFolderPath, string mediaFolderTmpPath, string prefixSuggestionImageName, string prefixSuggestionFileName)
        {
            string newFileName           = null;
            var    mediaAbsoluteBasePath = Path.Combine(env.WebRootPath, mediaFolderPath?.Replace("~/", string.Empty));

            try
            {
                if (suggestionModel == null)
                {
                    throw new ArgumentNullException("suggestionModel");
                }

                var currentSuggestion = await biblioEntities.Suggestions.FindAsync(suggestionModel.Id);

                if (currentSuggestion == null)
                {
                    throw new KeyNotFoundException("Suggestion");
                }

                bool   deleteCurrentFile     = false;
                string currentSuggestionFile = currentSuggestion.File;


                if (OssFile.HasFile(suggestionModel.FileUploaded))
                {
                    newFileName       = await OssFile.SaveFile(suggestionModel.FileUploaded, prefixSuggestionFileName, mediaAbsoluteBasePath);;
                    deleteCurrentFile = true;
                }
                else if (!string.IsNullOrEmpty(suggestionModel.FileUploadedName) &&
                         File.Exists(Path.Combine(mediaAbsoluteBasePath, suggestionModel.FileUploadedName)))
                {
                    newFileName = OssFile.GetNewFileName(suggestionModel.FileUploadedName, prefixSuggestionFileName);
                    File.Move
                    (
                        Path.Combine(mediaAbsoluteBasePath, suggestionModel.FileUploadedName),
                        Path.Combine(mediaAbsoluteBasePath, newFileName)
                    );
                    deleteCurrentFile = true;
                }
                else
                {
                    newFileName = currentSuggestion.File;
                }

                Suggestion newSuggestion = new Suggestion
                                           (
                    suggestionModel.Id,
                    suggestionModel.Subject,
                    suggestionModel.Message,
                    newFileName,
                    suggestionModel.IsRead,
                    suggestionModel.IsSolved,
                    currentSuggestion.Date,
                    currentSuggestion.UserId,
                    null
                                           );

                biblioEntities.Entry(currentSuggestion).CurrentValues.SetValues(newSuggestion);
                await biblioEntities.SaveChangesAsync();


                if (deleteCurrentFile)
                {
                    OssFile.DeleteFile(currentSuggestionFile, mediaAbsoluteBasePath);
                }

                return(new SuggestionModel(newSuggestion, mediaFolderPath, mediaFolderPath));
            }
            catch (Exception ex)
            {
                if (OssFile.HasFile(suggestionModel.FileUploaded) && !string.IsNullOrEmpty(newFileName))
                {
                    OssFile.DeleteFile(newFileName, mediaAbsoluteBasePath);
                }
                throw ex;
            }
        }