public BusinessResult <string> Upload(FileUploadDto file) { try { string ext = Path.GetExtension(file.fileName); var split = file.Base.Split(','); string fullPath = string.Empty; if (file.AllowedExtensions.FirstOrDefault(c => c.ToLower() == ext.ToLower()) != null) { string fileName = Guid.NewGuid().ToString().Replace("-", ""); DirectoryInfo di = Directory.CreateDirectory(System.Web.Hosting.HostingEnvironment.MapPath(file.SavePath)); var bytes = Convert.FromBase64String(string.Empty); if (split.Length > 1) { bytes = Convert.FromBase64String(split[1]); } fullPath = $"{di.FullName}/{fileName}{ext}"; using (var imageFile = new FileStream(fullPath, FileMode.Create)) { imageFile.Write(bytes, 0, bytes.Length); imageFile.Flush(); } return(BusinessResult <string> .Sucess($"{file.SavePath}/{fileName}{ext}", string.Empty)); } return(BusinessResult <string> .Issue(string.Empty, $"Archivo no permitido", null)); } catch (Exception ex) { return(BusinessResult <string> .Issue(string.Empty, $"Error subiendo el archivo {file.fileName} al servidor", ex)); } }
public BusinessResult <List <UserDTO> > GetAllSync() { try { return(BusinessResult <List <UserDTO> > .Success(_iuserModel.GetAllSync(), General.OperationSucsess)); } catch (Exception ex) { return(BusinessResult <List <UserDTO> > .Issue(null, General.OperationIssue, ex)); } }
public BusinessResult <CategoriaDto> Obtener(int id) { try { var result = _CategoriaData.Obtener(id); return(BusinessResult <CategoriaDto> .Success(result, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <CategoriaDto> .Issue(null, "Operación incorrecta", ex)); } }
public BusinessResult <bool> CategoriaEditar(CategoriaEditarDto objEdita) { try { var result = _CategoriaData.CategoriaEditar(objEdita); return(BusinessResult <bool> .Success(result, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <bool> .Issue(false, "Operación incorrecta", ex)); } }
public BusinessResult <bool> Update(CategoriaDto entityDto) { try { _icategoriadata.Update(entityDto); return(BusinessResult <bool> .Success(true, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <bool> .Issue(false, "Operación incorrecta", ex)); } }
public BusinessResult <List <ProductoDto> > GetAllBy(Expression <Func <ProductoDto, bool> > condition) { try { var result = _productoData.GetAllBy(condition); return(BusinessResult <List <ProductoDto> > .Success(result, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <List <ProductoDto> > .Issue(null, "Operación incorrecta", ex)); } }
public BusinessResult <ProductoDto> GetById(int id) { try { var result = _productoData.GetById(id); return(BusinessResult <ProductoDto> .Success(result, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <ProductoDto> .Issue(null, "Operación incorrecta", ex)); } }
public BusinessResult <CategoriaDto> Create(CategoriaDto entityDto) { try { var result = _icategoriadata.Create(entityDto); return(BusinessResult <CategoriaDto> .Success(result, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <CategoriaDto> .Issue(null, "Operación incorrecta", ex)); } }
public BusinessResult <bool> Delete(int id) { try { var result = _icategoriadata.Delete(id); return(BusinessResult <bool> .Success(true, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <bool> .Issue(false, "Operación incorrecta", ex)); } }
public BusinessResult <CategoriaDto> GetBy(Expression <Func <CategoriaDto, bool> > condition) { try { var result = _icategoriadata.GetBy(condition); return(BusinessResult <CategoriaDto> .Success(result, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <CategoriaDto> .Issue(null, "Operación incorrecta", ex)); } }
public BusinessResult <bool> eliminarCategoria(CategoriaEliminarDto objCategori) { try { var result = _CategoriaData.eliminarCategoria(objCategori); return(BusinessResult <bool> .Success(result, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <bool> .Issue(false, "Operación incorrecta", ex)); } }
public BusinessResult <CategoriaRegistroDto> CreateCategoria(CategoriaRegistroDto CategoiraRe) { try { var result = _CategoriaData.CreateCategoria(CategoiraRe); return(BusinessResult <CategoriaRegistroDto> .Success(result, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <CategoriaRegistroDto> .Issue(null, "Operación incorrecta", ex)); } }
/// <summary> /// Cuando ocurre un error en el sistema, este intenta borrar los datos para no consevar datos basura /// </summary> /// <param name="project"></param> public void RollBack(js_DNNJuliusForm project) { try { DNNJuliusFormData = new DNNJuliusFormData(); DNNJuliusFormData.RollBack(project); } catch (Exception ex) { BusinessResult <bool> .Issue(false, "Módulo form julius", ex); } }
public BusinessResult <List <CategoriaDto> > listarCategorias() { try { var result = _CategoriaData.listarCategorias(); return(BusinessResult <List <CategoriaDto> > .Success(result, "Operación correcta")); } catch (Exception ex) { return(BusinessResult <List <CategoriaDto> > .Issue(null, "Operación incorrecta", ex)); } }
public async Task <BusinessResult <bool> > Delete(int id) { try { var resultOperation = await _iuserModel.Delete(id); return(BusinessResult <bool> .Success(resultOperation, General.OperationSucsess)); } catch (Exception ex) { return(BusinessResult <bool> .Issue(false, General.OperationIssue, ex)); } }
public async Task <BusinessResult <List <StoreDTO> > > GetAll(int quantity = 0) { try { var result = await _istoreModel.GetAll(quantity); return(BusinessResult <List <StoreDTO> > .Success(result, General.OperationSucsess)); } catch (Exception ex) { return(BusinessResult <List <StoreDTO> > .Issue(null, General.OperationIssue, ex)); } }
public async Task <BusinessResult <UserDTO> > GetBy(Expression <Func <UserDTO, bool> > condition) { try { var resultOperation = await _iuserModel.GetBy(condition); return(BusinessResult <UserDTO> .Success(resultOperation, General.OperationSucsess)); } catch (Exception ex) { return(BusinessResult <UserDTO> .Issue(null, General.OperationIssue, ex)); } }
public async Task <BusinessResult <StoreDTO> > CreateAsync(StoreDTO entity) { try { var resultOperation = await _istoreModel.CreateAsync(entity); return(BusinessResult <StoreDTO> .Success(resultOperation, General.OperationSucsess)); } catch (Exception ex) { return(BusinessResult <StoreDTO> .Issue(null, General.OperationIssue, ex)); } }
public BusinessResult <List <string> > CalculateProcess(string[] elements) { try { var resultTrip = CalculateTrip(elements); return(BusinessResult <List <string> > .Success(resultTrip.Result, "Operación Correcta")); } catch (Exception ex) { return(BusinessResult <List <string> > .Issue(null, "Operación Incorrecta", ex)); } }
/// <summary> /// Guarda en el formulario la información del archivo /// </summary> /// <param name="model"></param> /// <returns></returns> public BusinessResult <js_DNNJuliusFormArchivo> AddFile(js_DNNJuliusFormArchivo model) { try { DNNJuliusFormData = new DNNJuliusFormData(); var add = DNNJuliusFormData.AddFile(model); return(BusinessResult <js_DNNJuliusFormArchivo> .Sucess(add, string.Empty)); } catch (Exception ex) { return(BusinessResult <js_DNNJuliusFormArchivo> .Issue(null, "Error guardando formulario de Julius Form's", ex)); } }
public async Task <BusinessResult <List <StoreDTO> > > GetAllBy(Expression <Func <StoreDTO, bool> > condition) { try { var result = await _istoreModel.GetAllBy(condition); return(BusinessResult <List <StoreDTO> > .Success(result, General.OperationSucsess)); } catch (Exception ex) { return(BusinessResult <List <StoreDTO> > .Issue(null, General.OperationIssue, ex)); } }
public async Task <BusinessResult <UserDTO> > GetById(int id) { try { var resultOperation = await _iuserModel.GetById(id); return(BusinessResult <UserDTO> .Success(resultOperation, General.OperationSucsess)); } catch (Exception ex) { return(BusinessResult <UserDTO> .Issue(null, General.OperationIssue, ex)); } }
public async Task <BusinessResult <bool> > EditAsync(StoreDTO entity) { try { var resultOperation = await _istoreModel.EditAsync(entity); return(BusinessResult <bool> .Success(true, General.OperationSucsess)); } catch (Exception ex) { return(BusinessResult <bool> .Issue(false, General.OperationIssue, ex)); } }
public BusinessResult <List <js_City> > GetCities(int departamentId) { try { using (var context = new Model.Model()) { var data = context.js_City.Where(c => c.Show && c.IdDepartament == departamentId); return(BusinessResult <List <js_City> > .Sucess(data.ToList(), string.Empty)); } } catch (Exception ex) { return(BusinessResult <List <js_City> > .Issue(null, "Error obteniendo las ciudades de la BD", ex)); } }
/// <summary> /// En este caso este metodo calcula la cantidad de viajes que realiza por día. /// </summary> /// <param name="elementsDay"></param> /// <returns></returns> private BusinessResult <List <string> > CalculateTrip(string[] elementsDay) { try { var resultElements = GetElementsDay(elementsDay); var trip = new List <string>(); int counTrip = 0; int day = 0; var WeightMin = int.Parse(ConfigurationManager.AppSettings["WeightMin"]); foreach (var item in resultElements.Result) { day++; var list = item.OrderByDescending(x => x).ToList(); for (int i = 0; i < list.Count; i++) { if (list[i] <= WeightMin) { int cont = 2; var operador = 0; if (i == list.Count - 1 && list[1] < WeightMin) { break; } while (operador <= WeightMin) { operador = list[i] * cont; cont++; } counTrip++; int delete = cont - 2; list = list.Take(list.Count() - delete).ToList(); } else { counTrip++; } } var result = String.Format("{0} {1}: {2}", "Case #", day, counTrip); trip.Add(result); counTrip = 0; } return(BusinessResult <List <string> > .Success(trip, "Operación Correcta")); } catch (Exception ex) { return(BusinessResult <List <string> > .Issue(null, "Operación Incorrecta", ex)); } }
/// <summary> /// Este metodo crea una lista separando los elementos a procesar por dia. /// </summary> /// <param name="elements"></param> /// <returns></returns> private BusinessResult <List <List <int> > > GetElementsDay(string[] elements) { try { int workDay = Convert.ToInt32(elements[0]); if (workDay > int.Parse(ConfigurationManager.AppSettings["WorkDay"])) { throw new Exception("El número de días supera el máximo permitido"); } int elementos = Convert.ToInt32(elements[1]); if (workDay > int.Parse(ConfigurationManager.AppSettings["Elements"])) { throw new Exception("El número elementos supera el máximo permitido"); } var element = new List <int>(); var days = new List <List <int> >(); var limit = elementos + 1; for (int i = 2; i < elements.Length; i++) { if (elements[i] != "") { if (i > limit) { days.Add(element); if (i < elements.Length) { limit = limit + Convert.ToInt32(elements[i]) + 1; } element = new List <int>(); } else { element.Add(Convert.ToInt32(elements[i])); } } } days.Add(element); return(BusinessResult <List <List <int> > > .Success(days, "Operación Correcta")); } catch (Exception ex) { return(BusinessResult <List <List <int> > > .Issue(null, "Operación Incorrecta", ex)); } }
public BusinessResult <List <js_Departament> > GetDepartaments(int countryId) { try { //new Exception(); using (var context = new Model.Model()) { var data = context.js_Departament.Where(c => c.Show && c.IdCountry == countryId); return(BusinessResult <List <js_Departament> > .Sucess(data.ToList(), string.Empty)); } } catch (Exception ex) { return(BusinessResult <List <js_Departament> > .Issue(null, "Error obteniendo los departamentos de la BD", ex)); } }
public async Task <BusinessResult <UserTripsDto> > SaveProcess(int document, string urlProcess) { try { var userTripsDto = new UserTripsDto() { Document = document, DateProcess = System.DateTime.Now, UrlFileProcess = urlProcess }; var result = await _iusertripsdata.CreateAsync(userTripsDto); return(BusinessResult <UserTripsDto> .Success(result, "Operación Correcta")); } catch (Exception ex) { return(BusinessResult <UserTripsDto> .Issue(null, "Operación Incorrecta", ex)); } }
public async Task <BusinessResult <bool> > EditAsync(UserDTO entity) { try { if (!ValidatePassword(entity.UserPass)) { throw new UserException(General.InvalidPassword); } entity.UpdateDate = DatetimeHelper.GetCurrentColombianTime(); var resultOperation = await _iuserModel.EditAsync(entity); return(BusinessResult <bool> .Success(resultOperation, General.OperationSucsess)); } catch (UserException user) { return(BusinessResult <bool> .Issue(false, user.Message, user)); } catch (GenericADOException ex) { var sql = ex.InnerException as SqlException; if (sql != null && sql.Number == 2627) { // Here's where to handle the unique constraint violation return(BusinessResult <bool> .Issue(false, General.UniqueUserName, sql)); } else { return(BusinessResult <bool> .Issue(false, General.OperationIssue, sql)); } } catch (Exception ex) { return(BusinessResult <bool> .Issue(false, General.OperationIssue, ex)); } }
/// <summary> /// Envía correo electrónico a el usuario /// </summary> /// <param name="PE"></param> public BusinessResult <bool> SendEmail(DNNJuliusFormDto PE, List <FileUploadDto> files) { try { List <Attachment> attachment = new List <Attachment>(); string Plantilla = File.ReadAllText($"{HttpRuntime.AppDomainAppPath}{ThemeEmail}"); Plantilla = Plantilla.Replace("{{niu}}", PE.CodigoNiu); Plantilla = Plantilla.Replace("{{factibilidad}}", PE.Factibilidad); Plantilla = Plantilla.Replace("{{observaciones}}", PE.Observaciones); Plantilla = Plantilla.Replace("{{strNombreUsuario}}", PE.NombreRazonSocial); Plantilla = Plantilla.Replace("{{nombresS}}", PE.NombreRazonSocial); Plantilla = Plantilla.Replace("{{tipoDocumentoS}}", PE.TipoDocumentoSolicitante); Plantilla = Plantilla.Replace("{{documentoIdentidadS}}", PE.DocumentoIdentidadSolicitante); Plantilla = Plantilla.Replace("{{direccionS}}", PE.DireccionSolicitante); Plantilla = Plantilla.Replace("{{municipioS}}", GetCityNameById(string.IsNullOrEmpty(PE.DepartamentoSolicitante) ? 0 : Convert.ToInt32(PE.DepartamentoSolicitante), string.IsNullOrEmpty(PE.MunicipioSolicitante) ? 0 : Convert.ToInt32(PE.MunicipioSolicitante))); Plantilla = Plantilla.Replace("{{DepartamentoS}}", GetDepartamentNameById(string.IsNullOrEmpty(PE.DepartamentoSolicitante) ? 0 : Convert.ToInt32(PE.DepartamentoSolicitante))); Plantilla = Plantilla.Replace("{{telefonoS}}", PE.TelefonoSolicitante); Plantilla = Plantilla.Replace("{{celularS}}", PE.CelularSolicitante); Plantilla = Plantilla.Replace("{{emailS}}", PE.EmailSolicitante); Plantilla = Plantilla.Replace("{{nombresP}}", PE.NombrePropietario); Plantilla = Plantilla.Replace("{{tipoDocumentoP}}", PE.TipoDocumentoPropietario); Plantilla = Plantilla.Replace("{{documentoIdentidadP}}", PE.DocumentoIdentidadPropietario); Plantilla = Plantilla.Replace("{{direccionP}}", PE.DireccionPropietario); Plantilla = Plantilla.Replace("{{departamentoP}}", GetDepartamentNameById(string.IsNullOrEmpty(PE.DepartamentoPropietario) ? 0 : Convert.ToInt32(PE.DepartamentoPropietario))); Plantilla = Plantilla.Replace("{{municipioP}}", GetCityNameById(string.IsNullOrEmpty(PE.DepartamentoPropietario) ? 0 : Convert.ToInt32(PE.DepartamentoPropietario), string.IsNullOrEmpty(PE.MunicipioPropietario) ? 0 : Convert.ToInt32(PE.MunicipioPropietario))); Plantilla = Plantilla.Replace("{{telefonoP}}", PE.TelefonoPropietario); Plantilla = Plantilla.Replace("{{celularP}}", PE.CelularPropietario); Plantilla = Plantilla.Replace("{{emailP}}", PE.EmailPropietario); Plantilla = Plantilla.Replace("{{nombreO}}", PE.NombreObra); Plantilla = Plantilla.Replace("{{direccionO}}", PE.DireccionObra); Plantilla = Plantilla.Replace("{{estratoO}}", PE.EstratoObra.ToString()); Plantilla = Plantilla.Replace("{{nombresI}}", PE.NombreIngeniero); Plantilla = Plantilla.Replace("{{documentoI}}", PE.DocumentoIdentidadIngeniero); Plantilla = Plantilla.Replace("{{MatriculaProfesionalI}}", PE.MatriculaProfesionalIngeniero); Plantilla = Plantilla.Replace("{{respuesta}}", (PE.Respuesta) ? "Sí" : "No"); Mail.SendEmail(FromEmail, FromEmail, PE.EmailSolicitante, SubjectEmail, Plantilla, attachment); if (files != null && files.Count > 0) { foreach (var item in files) { var read = File.ReadAllBytes($"{HttpRuntime.AppDomainAppPath}{item.SavePath.Replace("~", "")}"); Stream stream = new MemoryStream(read); attachment.Add(new Attachment(stream, item.fileName)); stream.Close(); } } var split = CopyEmail.Split(';'); if (split != null && split.Count() > 0) { foreach (var item in split) { Mail.SendEmail(FromEmail, FromEmail, item.Trim(), SubjectEmail, Plantilla, attachment); } } return(BusinessResult <bool> .Sucess(true, string.Empty)); } catch (Exception ex) { return(BusinessResult <bool> .Issue(false, string.Empty, ex)); } }