public ActionResult AddOrganization(EditOrganizationModel model, FormCollection collection, int id = 0) { if (ModelState.IsValid) { bool r; if (id > 0) { r = YunClient.Instance.Execute(new UpdateOrganizationRequest { Description = model.Description, Id = id, Name = model.Name, ParentId = collection["OrganizationId"].TryTo(0), Sort = model.Sort }, Token).Result; return(Json(r ? 1 : 0)); } r = YunClient.Instance.Execute(new AddOrganizationRequest { Description = model.Description, Name = model.Name, ParentId = collection["OrganizationId"].TryTo(0), Sort = model.Sort }, Token).Result > 0; return(Json(r ? 1 : 0)); } return(Json(-1)); }
public IActionResult CreateOrganization() { EditOrganizationModel model = new EditOrganizationModel(); model.EntityMeta = _entityFinder.FindByName("organization"); model.Attributes = _attributeFinder.FindByEntityId(model.EntityMeta.EntityId); model.State = (int)RecordState.Enabled; model.LanguageList = _languageService.Query(n => n.Sort(s => s.SortAscending(f => f.UniqueId))); model.Datas = new Entity("organization"); return(View(model)); }
public ActionResult Edit(Guid id, Guid?versionId) { try { var organization = this.GetEntity <Organization>(id); if (organization == null) { TempData["error"] = Locale.OrganizationNotFound; return(RedirectToAction("Index")); } if (organization.Tags.Any(t => t.TagKey == Constants.ImportedDataTag && t.Value?.ToLower() == "true")) { this.TempData["warning"] = Locale.RecordMustBeVerifiedBeforeEditing; return(RedirectToAction("ViewOrganization", new { id, versionId })); } var relationships = new List <EntityRelationship>(); relationships.AddRange(this.GetEntityRelationships <ManufacturedMaterial>(organization.Key.Value, r => (r.RelationshipTypeKey == EntityRelationshipTypeKeys.Instance || r.RelationshipTypeKey == EntityRelationshipTypeKeys.ManufacturedProduct) && r.ObsoleteVersionSequenceId == null).ToList()); organization.Relationships = relationships.Intersect(organization.Relationships, new EntityRelationshipComparer()).ToList(); var industryConceptSet = this.GetConceptSet(ConceptSetKeys.IndustryCode); var model = new EditOrganizationModel(organization) { IndustryConcepts = industryConceptSet?.Concepts.ToSelectList(this.HttpContext.GetCurrentLanguage()).ToList(), UpdatedBy = this.GetUserEntityBySecurityUserKey(organization.CreatedByKey.Value)?.GetFullName(NameUseKeys.OfficialRecord) }; return(View(model)); } catch (Exception e) { Trace.TraceError($"Unable to retrieve organization: {e}"); this.TempData["error"] = Locale.UnexpectedErrorMessage; } return(RedirectToAction("Index")); }
public IActionResult Post(EditOrganizationModel model) { string msg = string.Empty; if (ModelState.IsValid) { Entity entity = new Entity("organization"); entity.SetIdValue(model.OrganizationId.Value); entity.SetAttributeValue("Name", model.Name); entity.SetAttributeValue("LanguageId", (int)model.LanguageId); //entity.SetAttributeValue("State", model.State); entity.SetAttributeValue("Description", model.Description); entity.SetAttributeValue("BaseCurrencyId", new EntityReference("currency", model.BaseCurrencyId)); entity.SetAttributeValue("ManagerId", model.ManagerId); _dataUpdater.Update(entity); return(JOk(T["saved_success"])); } msg = GetModelErrors(ModelState); return(JError(T["saved_error"] + ": " + msg)); }
public IActionResult CreateOrganization(EditOrganizationModel model) { string msg = string.Empty; if (ModelState.IsValid) { Entity entity = new Entity("organization"); entity.SetIdValue(Guid.NewGuid()); entity.SetAttributeValue("Name", model.Name); entity.SetAttributeValue("LanguageId", (int)model.LanguageId); entity.SetAttributeValue("State", model.State); entity.SetAttributeValue("Description", model.Description); entity.SetAttributeValue("BaseCurrencyId", new EntityReference("currency", model.BaseCurrencyId)); entity.SetAttributeValue("ManagerId", model.ManagerId); var id = _dataCreater.Create(entity); return(JOk(T["created_success"], new { id = id })); } msg = GetModelErrors(ModelState); return(JOk(T["created_error"] + ": " + msg)); }
public ActionResult Edit(EditOrganizationModel model) { try { if (ModelState.IsValid) { var organization = this.GetEntity <Organization>(model.Id, model.VersionKey, m => m.ClassConceptKey == EntityClassKeys.Organization && m.ObsoletionTime == null); if (organization == null) { TempData["error"] = Locale.OrganizationNotFound; return(RedirectToAction("Index")); } var organizationToUpdate = model.ToOrganization(organization); organizationToUpdate.CreatedByKey = Guid.Parse(this.User.Identity.GetUserId()); var updatedOrganization = this.ImsiClient.Update <Organization>(organizationToUpdate); TempData["success"] = Locale.OrganizationUpdatedSuccessfully; return(RedirectToAction("ViewOrganization", new { id = updatedOrganization.Key, versionId = updatedOrganization.VersionKey })); } } catch (Exception e) { Trace.TraceError($"Unable to update organization: {e}"); } var industryConceptSet = this.GetConceptSet(ConceptSetKeys.IndustryCode); model.IndustryConcepts = industryConceptSet?.Concepts.ToSelectList(this.HttpContext.GetCurrentLanguage()).ToList(); TempData["error"] = Locale.UnableToUpdateOrganization; return(View(model)); }
public IActionResult ManageOrganization(EditOrganizationModel model) { ManageOrganizationModel mog = new() { Organization = _db.GetOrganization(model.Id), LoggedInUser = this.GetLoggedInUserByEmail(_db) }; mog.Workers = _db.GetAllOrganizationUsers(mog.Organization.Id); if (ModelState.IsValid == false) { mog.DidUpdateOrg = "False"; return(View(mog)); } mog.Organization.Description = model.Description; mog.Organization.Name = model.Name; mog.DidUpdateOrg = _db.UpdateOrganization(mog.Organization).ToString(); return(View(mog)); }
public IActionResult Get(Guid id) { if (id.Equals(Guid.Empty)) { return(NotFound()); } EditOrganizationModel model = new EditOrganizationModel(); model.OrganizationId = id; model.EntityMeta = _entityFinder.FindByName("organization"); model.Attributes = _attributeFinder.FindByEntityId(model.EntityMeta.EntityId); model.LanguageList = _languageService.Query(n => n.Where(f => f.StateCode == RecordState.Enabled).Sort(s => s.SortAscending(f => f.UniqueId))); model.Datas = _dataFinder.RetrieveById("organization", id); model.Datas["manageridname"] = string.Empty; if (!model.Datas.GetGuidValue("managerid").Equals(Guid.Empty)) { var manager = _dataFinder.RetrieveById("systemuser", model.Datas.GetGuidValue("managerid")); if (manager != null && manager.Count > 0) { model.Datas["manageridname"] = manager.GetStringValue("name"); } } return(JOk(model)); }