public ActionResult SaveAssignTag(string id, string list, string name, string category, string type, string quantityTagsToValidate, string categoryTagsToValidate) { var user = User as ApplicationUser; try { var tagUi = new DataTagUi { Id = id, Entity = type }; _tagUiLogic.SaveNewSelectedTag(tagUi, list, name, category, type, user); } catch (Exception exception) { if (user != null) { _log.ErrorFormat("Current User: {0} - An exception occurred with the following message: {1}", user.UserName, exception.Message); } if (!ExceptionHandler.Manage(exception, this, Layer.UILogic)) { return(RedirectToAction("Error", "Errors")); } } return(null); }
public DataTagUi GetAllDataTagUIInformation(string id, string entity) { var result = new DataTagUi(); var tagUi = new DataTagUi { Id = id, Entity = entity }; tagUi = NewSelectedTag(tagUi); if (tagUi != null) { result = tagUi; } if (result.TagsEntity == null) { result.TagsEntity = new List <Tag>(); } return(result); }
public ActionResult AssignTag(string id, string entity, string validateQuantityTags, string validateCategoryTags) { var tagUi = new DataTagUi { Id = id, Entity = entity }; try { ViewBag.QuantityTagsToValidate = validateQuantityTags; ViewBag.CategoryTagsToValidate = validateCategoryTags; var tagUiResponse = _tagUiLogic.NewSelectedTag(tagUi); return(PartialView("AssignTag", tagUiResponse)); } catch (Exception exception) { var user = User as ApplicationUser; if (user != null) { _log.ErrorFormat("Current User: {0} - An exception occurred with the following message: {1}", user.UserName, exception.Message); } if (!ExceptionHandler.Manage(exception, this, Layer.UILogic)) { return(RedirectToAction("Error", "Errors")); } } var currentController = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); return(RedirectToAction("Index", currentController)); }
public void SaveNewSelectedTag(DataTagUi tagUi, string list, string name, string category, string type, ApplicationUser creatorPrincipal) { if (creatorPrincipal == null) { throw new ArgumentNullException("creatorPrincipal"); } try { tagUi.AllTags = GetSelectedTag(type, list); tagUi.TagsCategories = GetNewTagCategory(name, category); var modelTags = tagUi.AllTags as Tag[] ?? tagUi.AllTags.ToArray(); if (modelTags.Any()) { var entityTags = ToCommonTags(modelTags, creatorPrincipal); var entityId = Guid.Parse(tagUi.Id); var clear = true; switch (tagUi.Entity) { case UITaggableEntity.User: _tagBusinessLogic.AssignTags <User>(entityId, entityTags, clear); break; case UITaggableEntity.ItemRegistration: _tagBusinessLogic.AssignTags <ItemRegistration>(entityId, entityTags, clear); break; default: var thisType = ToModelTagType(tagUi.Entity); var genericType = CreateGenericType(thisType); var method = typeof(TagUILogic).GetMethod("AssignTags", new[] { typeof(Guid), typeof(IList <Lok.Unik.ModelCommon.Client.Tag>), typeof(bool) }); var genericMethod = method.MakeGenericMethod(new[] { genericType.GetType() }); var result = genericMethod.Invoke(this, new object[] { entityId, entityTags, clear }); break; } } if (tagUi.TagsCategories.Count() != 0) { var tagsCategory = tagUi.TagsCategories; var tags = CollectTagCategories(tagUi.Entity, tagsCategory); switch (tagUi.Entity) { case UITaggableEntity.User: _tagBusinessLogic.AssignTags <User>(Guid.Parse(tagUi.Id), ToCommonTags(tags, creatorPrincipal), false); break; case UITaggableEntity.ItemRegistration: _tagBusinessLogic.AssignTags <ItemRegistration>(Guid.Parse(tagUi.Id), ToCommonTags(tags, creatorPrincipal), false); break; default: var thisType = ToModelTagType(tagUi.Entity); var genericType = CreateGenericType(thisType); var method = typeof(TagUILogic).GetMethod("AssignTags", new[] { typeof(Guid), typeof(IList <Lok.Unik.ModelCommon.Client.Tag>), typeof(bool) }); var genericMethod = method.MakeGenericMethod(new[] { genericType.GetType() }); genericMethod.Invoke(this, new object[] { Guid.Parse(tagUi.Id), ToCommonTags(tags, creatorPrincipal), false }); break; } } } catch (Exception exception) { _log.ErrorFormat("An Exception occurred with the following message: {0} \n {1}", exception.ToString(), exception.InnerException == null ? string.Empty : "InnerException: " + exception.InnerException.ToString()); throw new ApplicationException("Error saving new tag", exception); } }
public DataTagUi NewSelectedTag(DataTagUi tagUi) { try { var tagUiResponse = new DataTagUi { Entity = tagUi.Entity }; var categories = _tagCategoryUiLogic.GetAllTagCategories(); tagUiResponse.TagsCategories = categories; var categoriesColor = new List <KnownColor> { KnownColor.Transparent }; switch (tagUi.Entity) { case UITaggableEntity.User: tagUiResponse.AllTags = GetTagsExceptByCategoryColor <User>(categoriesColor); var test = GetAllTagsByEntity <User>(); var userTags = GetAllTagsByEntity <User>(new Guid(tagUi.Id)); userTags = userTags.Where(t => t.Color != KnownColor.Transparent.ToString()).ToList(); tagUiResponse.Id = tagUi.Id; tagUiResponse.TagsEntity = userTags; break; case UITaggableEntity.ItemRegistration: tagUiResponse.AllTags = GetTagsExceptByCategoryColor <ItemRegistration>(categoriesColor); var itemRegistrationTags = GetAllTagsByEntity <ItemRegistration>(new Guid(tagUi.Id)); userTags = itemRegistrationTags.Where(t => t.Color != KnownColor.Transparent.ToString()).ToList(); tagUiResponse.Id = tagUi.Id; tagUiResponse.TagsEntity = userTags; break; default: var thisType = ToModelTagType(tagUi.Entity); var genericType = CreateGenericType(thisType); var getAllTagsByEntityMethod = typeof(TagUILogic).GetMethod("GetTagsExceptByCategoryColor", new Type[] { typeof(List <KnownColor>) }); var genericMethodMaker = getAllTagsByEntityMethod.MakeGenericMethod(new[] { genericType.GetType() }); tagUiResponse.AllTags = ((IEnumerable <Tag>)genericMethodMaker.Invoke(this, new object[] { categoriesColor })).ToList(); var method = typeof(TagUILogic).GetMethod("GetAllTagsByEntity", new[] { typeof(Guid) }); var genericMethod = method.MakeGenericMethod(new[] { genericType.GetType() }); var methodInvoke = genericMethod.Invoke(this, new object[] { Guid.Parse(tagUi.Id) }); userTags = ((List <Tag>)methodInvoke).Where(t => t.Color != KnownColor.Transparent.ToString()).ToList(); tagUiResponse.Id = tagUi.Id; tagUiResponse.TagsEntity = userTags; break; } return(tagUiResponse); } catch (Exception exception) { if (exception.InnerException != null) { _log.ErrorFormat("An Exception occurred with the following message: {0}", exception.ToString()); _log.ErrorFormat("\n InnerException: {0}", exception.InnerException.ToString()); } else { _log.ErrorFormat("An Exception occurred with the following message: {0}", exception.ToString()); } return(null); } }