public ActionResult CalculateSum(HttpPostedFileBase file, FileCheckSumType type) { if (file == null || file.ContentLength == 0) { return View("CheckSumResult", ResponseModel.ErrorResponse("No file selected")); } var fileName = "file_" + Guid.NewGuid().ToString(); var filePath = Path.Combine(Server.MapPath("~/App_Data/"), fileName); file.SaveAs(filePath); var response = PrepareResponse(filePath, type); RemoveFileIfExist(filePath); return View("CheckSumResult", response); }
private ResponseModel PrepareResponse(string filePath, FileCheckSumType type) { var responseModel = new ResponseModel(); try { switch (type) { case FileCheckSumType.MD5: responseModel.Data = EncryptLibrary.CheckSum.CalculateMD5(filePath); break; case FileCheckSumType.SHA1: responseModel.Data = EncryptLibrary.CheckSum.CalculateSHA1(filePath); break; } responseModel.Result = true; } catch (Exception) { responseModel.Data = "Error on checksum calculating"; } return responseModel; }