public static void InitializeData() { // Console.WriteLine("Init"); foreach (ItemEN i in itemCEN.BuscarTodos(0, -1)) { if (i.EsValido == EstadoEnum.enProceso) { changed_ids.Add(i.Id); itemCEN.Modificar(i.Id, i.Nombre, i.Descripcion, i.Imagen, EstadoEnum.descartado, 10); // Console.WriteLine("Mod " + i.Id); } } for (int i = 0; i < new_elements; i++) { int id = itemCEN.Crear("Item Test", "Item Test", "TEST IMG", -1, -1); item = itemCEN.BuscarPorId(id); itemCEN.Modificar(id, item.Nombre, item.Descripcion, item.Imagen, EstadoEnum.enProceso, 10); ids.Add(id); // Console.WriteLine("Added " + id); } }
public void WhenModificoLosDatosDeEsteItem() { itemCEN.Modificar(itemId, item.Nombre + " modificado", item.Descripcion, item.Imagen, item.EsValido, 10); }
public void GivenTengoUnItemSinDescartar() { itemCEN.Modificar(id, item.Nombre, item.Descripcion, item.Imagen, EstadoEnum.enProceso, 10); }
public HttpResponseMessage Modificar(int idItem, [FromBody] ItemDTO dto) { // CAD, CEN, returnValue ItemRESTCAD itemRESTCAD = null; ItemCEN itemCEN = null; ItemDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); itemRESTCAD = new ItemRESTCAD(session); itemCEN = new ItemCEN(itemRESTCAD); // Modify itemCEN.Modificar(idItem, dto.Nombre , dto.Descripcion , dto.Imagen , dto.EsValido , dto.Puntuacion ); // Return modified object returnValue = ItemAssembler.Convert(itemRESTCAD.ReadOIDDefault(idItem), session); SessionCommit(); } catch (Exception e) { SessionRollBack(); if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 404 - Not found if (returnValue == null) { return(this.Request.CreateResponse(HttpStatusCode.NotFound)); } // Return 200 - OK else { response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue); return(response); } }
public async Task <HttpResponseMessage> UploadImage(int p_oid) { ItemCEN itemCEN = new ItemCEN(); ItemEN item = null; Dictionary <string, object> dict = new Dictionary <string, object>(); try { var httpRequest = HttpContext.Current.Request; foreach (string file in httpRequest.Files) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); var postedFile = httpRequest.Files [file]; if (postedFile != null && postedFile.ContentLength > 0) { int MaxContentLength = 1024 * 1024 * 5; //Size = 1 MB IList <string> AllowedFileExtensions = new List <string> { ".jpg", ".jpeg", ".png" }; var ext = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.')); var extension = ext.ToLower(); if (!AllowedFileExtensions.Contains(extension)) { var message = string.Format("Please Upload image of type .jpg,.gif,.png."); dict.Add("error", message); return(Request.CreateResponse(HttpStatusCode.BadRequest, dict)); } else if (postedFile.ContentLength > MaxContentLength) { var message = string.Format("Please Upload a file upto 1 mb."); dict.Add("error", message); return(Request.CreateResponse(HttpStatusCode.BadRequest, dict)); } else { string imageName = p_oid + Path.GetExtension(postedFile.FileName); var filePath = HttpContext.Current.Server.MapPath("~/ItemsImages"); bool exists = System.IO.Directory.Exists(filePath); if (!exists) { System.IO.Directory.CreateDirectory(filePath); } var final_path = filePath + "/" + imageName; postedFile.SaveAs(final_path); item = itemCEN.BuscarPorId(p_oid); itemCEN.Modificar(p_oid, item.Nombre, item.Descripcion, final_path, item.EsValido, item.Puntuacion); } } var message1 = string.Format("Image Updated Successfully."); return(Request.CreateErrorResponse(HttpStatusCode.Created, message1));; } var res = string.Format("Please Upload a image."); dict.Add("error", res); return(Request.CreateResponse(HttpStatusCode.NotFound, dict)); } catch (Exception ex) { var res = string.Format("some Message"); dict.Add("error", res); return(Request.CreateResponse(HttpStatusCode.NotFound, dict)); } }