예제 #1
0
 public ActionResult Create(Control instance)
 {
     ActionResult ar = VerifyIfProjectSelected("PRJNAME");
     if (null != ar) return ar;
     ViewBag.Title = "Create Control";
     ClearSessions();
     string requestKey = Request.Form.Keys[Request.Form.Keys.Count - 1] as string;
     if (requestKey.Contains(".")) requestKey = requestKey.Substring(0, requestKey.IndexOf("."));
     if (requestKey == "save")
     {
         if (ModelState.IsValid)
         {
             string log = "";
             this.ControlService.CurrentProjectId = (int)Session["PID"];
             bool isSuccess = this.ControlService.AddControl(instance.ControlProperty.Type,instance.ControlProperty.Property,instance.PropertyValue,instance.Name, out log);
             if (isSuccess)
             {
                 Session["HasQueried_c"] = null;
                 return RedirectToAction("Index");
             }
             ViewBag.Log = log;
         }
         return View("Create", new Control());
     }
     Session["Log_c"] = null;
     Session["HasQueried_c"] = null;
     return RedirectToAction("Index");
 }
예제 #2
0
 public bool AddControl(string controlType, string controlProperty, string propertyValue, string controlName, out string log)
 {
     Guard.ArgumentNotNullOrEmpty(controlType, "controlType");
     Guard.ArgumentNotNullOrEmpty(controlProperty, "controlProperty");
     if (null == propertyValue) propertyValue = "";
     Guard.ArgumentNotNullOrEmpty(controlName, "controlName");
     int pid = (this.CurrentProjectId > 0) ? this.CurrentProjectId : 1;
     bool isUnique = this.ControlRepository.IsControlNameUniqueInSameTypeAndProperty(pid, controlType, controlProperty, controlName);
     if (isUnique)
     {
         log = "done.";
         int propId = this.ControlPropertyRepository.QueryPropertyId(controlType,controlProperty);
         Control instance = new Control();
         instance.ProjectId = pid;
         instance.PropertyId = propId;
         instance.PropertyValue = propertyValue;
         instance.Name = controlName;
         return this.ControlRepository.AddControl(instance,out log);
     }
     else
     {
         log = "Fail to Add.The control name should be unique for " + controlType + " in Project " + pid.ToString();
     }
     return isUnique ;
 }
예제 #3
0
 private ActionResult Save(Control updatedItem,int pageIndex)
 {
     int cid = updatedItem.Id;
     if (null != updatedItem.Name || null != updatedItem.ControlProperty.Property)
     {
         this.ControlService.CurrentProjectId = (int)Session["PID"];
         string log = "";
         bool isSuccess = this.ControlService.UpdateControl(cid,updatedItem.ControlProperty.Type,
             updatedItem.ControlProperty.Property,updatedItem.PropertyValue,updatedItem.Name, out log);
         if (isSuccess)
         {
             Session["Log_c"] = null;
             Session["UpdatedId_c"] = null;
             Session["PropertyListWhenEdit"] = null;
             return RedirectToAction("Index", new { pageIndex = pageIndex });
         }
         Session["Log_c"] = log;
         return Edit(cid, updatedItem.ControlProperty.Property, pageIndex);
     }
     Session["Log_c"] = "Control Type, Property, Name Required!";
     return Edit(cid, updatedItem.ControlProperty.Property, pageIndex);
 }
예제 #4
0
 public bool UpdateControl(int id, string controlType, string controlProperty, string newPropertyValue, string newName, out string log)
 {
     Guard.ArgumentNotNullOrEmpty(controlType, "controlType");
     Guard.ArgumentNotNullOrEmpty(controlProperty, "controlProperty");
     if (null == newPropertyValue) newPropertyValue = "";
     Guard.ArgumentNotNullOrEmpty(newName, "controlName");
     int pid = (this.CurrentProjectId > 0) ? this.CurrentProjectId : 1;
     string property = this.GetControlPropertyById(id);
     string controlName = this.ControlRepository.GetControlById(id).Name;
     bool isUnique = true;
     bool ifChanged = (property.Equals(controlProperty) && controlName.Equals(newName)) ? false : true;
     if (ifChanged)
     {
         isUnique = this.ControlRepository.IsControlNameUniqueInSameTypeAndProperty(pid, controlType, controlProperty, newName);
     }
     if (isUnique)
     {
         int propId = this.ControlPropertyRepository.QueryPropertyId(controlType, controlProperty);
         Control instance = new Control() { Id = id, ProjectId = pid, PropertyId = propId, PropertyValue = newPropertyValue, Name = newName };
         this.ControlRepository.UpdateControl(instance,out log);
     }
     else
     {
         log = "Fail to Update.The control name should be unique for " + controlType + " in Project " + pid.ToString();
     }
     return isUnique;
 }