public Goal Add(GoalUpsert obj) { string[] permittedExtensions = { ".jpg", ".jpeg", ".png" }; Goal goal = new Goal(); var ext1 = Path.GetExtension(obj.Image.FileName).ToLower(); if ((obj.Image != null && permittedExtensions.Contains(ext1))) { goal.Image = ImageHelper.UploadImageFile(_hostEnvironment, "wwwroot/Uploads/Goal", obj.Image); } goal.Name = obj.Name; goal.TopicID = obj.TopicID; goal.Fee = obj.Fee; goal.Currency = obj.Currency; return(goal); }
public Goal Update(Goal goal, GoalUpsert obj) { string[] permittedExtensions = { ".jpg", ".jpeg", ".png" }; goal.Name = obj.Name; goal.TopicID = obj.TopicID; goal.Fee = obj.Fee; goal.Currency = obj.Currency; if (obj.Image != null) { var ext = Path.GetExtension(obj.Image.FileName).ToLower(); if (permittedExtensions.Contains(ext)) { ImageHelper.DeleteImage(_hostEnvironment, @"Uploads\Goal", goal.Image.Replace("/Uploads/Goal/", "")); goal.Image = ImageHelper.UploadImageFile(_hostEnvironment, "wwwroot/Uploads/Goal", obj.Image); } } return(goal); }