Ejemplo n.º 1
0
 /// <summary>
 /// Add material group operation
 /// </summary>
 /// <param name="Model">-editor model(universal model for data exchange)</param>
 /// <returns>true- operation has done successful</returns>        
 public bool ADDMaterialGroup(EditorModel Model)
 {
     bool ret = true;
     MaterialGroups creation = new MaterialGroups{Name=Model.NewMaterialGroupName};
     try {
         DBBase.Context.MaterialGroups.Add(creation);
         DBBase.Context.SaveChanges();
     }
     catch{
         ret = false;
     }
     return ret;
 }
Ejemplo n.º 2
0
        public ActionResult CentralPageEditor(string id, EditorModel ReceiveModel)
        {
            if (ReceiveModel != null) {
                ReceiveModel.SaveData();
            }
            EditorModel model = new EditorModel();
            switch (id) {
                case "UpperMenu":{
                    model.Container = (int)GlobalThings.ContainerTypes.UpperMenu;
                    break;
                }
                case "LeftMenuUp":{
                    model.Container = (int)GlobalThings.ContainerTypes.LeftMenuUp;
                    break;
                }
                case "LeftMenuDown":{
                    model.Container = (int)GlobalThings.ContainerTypes.LeftMenuDown;
                    break;
                }
                case "RightMenuUp":{
                    model.Container = (int)GlobalThings.ContainerTypes.RightMenuUp;
                    break;
                }
                case "RightMenuDown":{
                    model.Container = (int)GlobalThings.ContainerTypes.RightMenuDown;
                    break;
                }
                case "CentralContent":{
                    model.Container = (int)GlobalThings.ContainerTypes.CentralContent;
                    break;
                }
                case "Footer":{
                    model.Container = (int)GlobalThings.ContainerTypes.Footer;
                    break;
                }

            }
            model.LoadData();
            return View(model);
        }
Ejemplo n.º 3
0
 public JsonResult MaterialsEditorJSON(EditorModel ReceiverModel)
 {
     EditorModel model = ReceiverModel;
     JsonResult ret = Json("ok");
     switch (ReceiverModel.cmd) {
         case "GetMaterialGroups": { /// Load material group list
             LoadMaterialGroupsToModel(model);
             ret = Json(model);
             break;
         }
         case "LoadMaterialListForSelectedGroup": { /// Load material list for selected material group
             LoadMaterialListForSelectedGroup(model);
             ret = Json(model);
             break;
         }
         case "LoadSelectedMaterial": { /// Load selected material
             LoadSelectedMaterial(model);
             ret = Json(model);
             break;
         }
         case "AddNewMaterialGroup": { /// Add new material group
             ADDMaterialGroup(model);
             ret = Json(model);
             break;
         }
         case "RenameMaterialGroup":{ /// Rename material group
             RenameMaterialGroup(model);
             ret = Json(model);
             break;
         }
         case "DeleteMaterialGroup":{ // Delete material group
             DeleteMaterialGroup(model);
             ret=Json(model);
             break;
         }
         case "AddNewMaterial":{ /// Add new material
             AddOrModifyMaterial(model);
             ret=Json(model);
             break;
         }
         case "RenameMaterial":{ /// Rename material
             RenameMaterial(model);
             ret=Json(model);
             break;
         }
         case "DeleteMaterial":{ /// Delete material
             DeleteMaterial(model);
             ret = Json(model);
             break;
         }
         case "UpdateMaterial": { /// Update material
             AddOrModifyMaterial(model);
             ret = Json(model);
             break;
         }
         case "GetServerPath":{ /// Get server path
             model.ServerPath = Server.MapPath("");
             ret = Json(model);
             break;
         }
     }
     return ret;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Add or modify material group
        /// <para>If there are no material with selected name, material would be created</para>
        /// <para>If material with selected name exist, it would be updated</para>
        /// </summary>
        /// <param name="Model">editor model(universal model for data exchange)</param>
        /// <returns>true- operation has done successful</returns>
        public bool AddOrModifyMaterial(EditorModel Model)
        {
            bool ret = true;
            var foundedMaterialGroup = DBBase.Context.MaterialGroups.SingleOrDefault(p => p.Name == Model.SelectedMaterialGroup);
            int DetectedMaterialGroupID;
            int DetectedUserID = GetUserIDByName(User.Identity.Name);
            if (foundedMaterialGroup != null)
            {
                DetectedMaterialGroupID = foundedMaterialGroup.MaterialGroupID;
                var foundedMaterial = DBBase.Context.Materials.SingleOrDefault(p => p.Name == Model.SelectedMaterial && p.MaterialGroupID == DetectedMaterialGroupID); //Выбираем материал по Имени и ID мат.групппы
                if (foundedMaterial == null)
                {
                    Materials creation = new Materials { MaterialGroupID = DetectedMaterialGroupID, Name = Model.NewMaterialName, HTML = Model.HTML, FirstCreatorID = DetectedUserID, LastModifierID = DetectedUserID, LastChange = DateTime.Now, isPublished = Model.isPublished };
                    DBBase.Context.Materials.Add(creation);
                    DBBase.Context.SaveChanges();
                }
                else { // Founded material
                    Materials Modification = DBBase.Context.Materials.SingleOrDefault(p => p.Name == Model.SelectedMaterial && p.MaterialGroupID == DetectedMaterialGroupID);
                    Modification.HTML = Model.HTML;
                    Modification.LastModifierID = DetectedUserID;
                    Modification.LastChange = DateTime.Now;
                    Modification.isPublished = Model.isPublished;
                    DBBase.Context.Entry(Modification).State = EntityState.Modified;
                    DBBase.Context.SaveChanges();
                }

            }
            return ret;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Rename material operation
 /// </summary>
 /// <param name="Model">editor model(universal model for data exchange)</param>
 /// <returns>true- operation has done successful</returns>
 public bool RenameMaterial(EditorModel Model)
 {
     bool ret = false;
     var foundedMaterialGroup = DBBase.Context.MaterialGroups.SingleOrDefault(p => p.Name == Model.SelectedMaterialGroup);
     if (foundedMaterialGroup != null) {
         var foundedMaterial = DBBase.Context.Materials.SingleOrDefault(p => p.Name == Model.SelectedMaterial && p.MaterialGroupID == foundedMaterialGroup.MaterialGroupID); //Выбираем материал по Имени и ID мат.групппы
         if (foundedMaterial != null) {
             foundedMaterial.Name = Model.NewMaterialName;
             DBBase.Context.Entry(foundedMaterial).State = System.Data.Entity.EntityState.Modified;
             DBBase.Context.SaveChanges();
         }
     }
     return ret;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Rename material group operation
 /// </summary>
 /// <param name="Model">-editor model(universal model for data exchange)</param>
 /// <returns>true- operation has done successful</returns>
 public bool RenameMaterialGroup(EditorModel Model)
 {
     bool ret = false;
     var foundedMaterialGroup = DBBase.Context.MaterialGroups.SingleOrDefault(p => p.Name == Model.SelectedMaterialGroup);
     if (foundedMaterialGroup != null) {
         foundedMaterialGroup.Name = Model.NewMaterialGroupName;
         DBBase.Context.Entry(foundedMaterialGroup).State = System.Data.Entity.EntityState.Modified;
         DBBase.Context.SaveChanges();
     }
     return ret;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Load selected material.
        /// <para>Load selected material by selected material group name and material name.</para>
        /// </summary>
        /// <param name="Model">editor model(universal model for data exchange)</param>
        public void LoadSelectedMaterial(EditorModel Model)
        {
            int DetectedMaterialGroup = DBBase.Context.MaterialGroups.SingleOrDefault(p => p.Name == Model.SelectedMaterialGroup).MaterialGroupID;
            var mat = DBBase.Context.Materials.SingleOrDefault(p => p.Name == Model.SelectedMaterial && p.MaterialGroupID == DetectedMaterialGroup);

            Model.HTML = mat.HTML;
            Model.FirstCreator = DBBase.Context.UserProfile.SingleOrDefault(p => p.UserId == mat.FirstCreatorID).UserName;
            Model.isPublished=mat.isPublished;
            if (mat.LastChange != null)
            {
                Model.LastChange = (DateTime)mat.LastChange;
            }
            Model.LastModifier=DBBase.Context.UserProfile.SingleOrDefault(p => p.UserId == mat.LastModifierID).UserName;
            Model.MaterialName = mat.Name;
            Model.SelectedMaterialID = mat.MaterialID;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Load material list for selected material group
 /// <para>You give class example to this procedure(with filled SelectedMaterialGroup) and your class example would be filled by list of materials for your group</para>
 /// </summary>
 /// <param name="model">editor model(universal model for data exchange). Use this class "as pointer"</param>
 public void LoadMaterialListForSelectedGroup(EditorModel model)
 {
     model.MaterialList = new List<string>();
     int DetectedMaterialGroup=DBBase.Context.MaterialGroups.SingleOrDefault(p=>p.Name==model.SelectedMaterialGroup).MaterialGroupID;
     var mat = DBBase.Context.Materials.Where(p => p.MaterialGroupID == DetectedMaterialGroup);
     foreach (var item in mat) {
         model.MaterialList.Add(item.Name);
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Load material group list operation
 /// <para>You give class example to this procedure and your class example would be filled by list of material groups</para>
 /// </summary>
 /// <param name="model">editor model(universal model for data exchange). Use this class "as pointer".</param>
 public void LoadMaterialGroupsToModel(EditorModel model)
 {
     model.MaterialGroupList = new List<string>();
     foreach (var item in DBBase.Context.MaterialGroups)
     {
         model.MaterialGroupList.Add(item.Name);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Delete material group operation
 /// </summary>
 /// Remove material group and all materials that has same MaterialGroupID
 /// <param name="Model">-editor model(universal model for data exchange)</param>
 /// <returns>true- operation has done successful</returns>
 public bool DeleteMaterialGroup(EditorModel Model)
 {
     bool ret = false;
     var itemToRemove = DBBase.Context.MaterialGroups.SingleOrDefault(p => p.Name == Model.SelectedMaterialGroup);
     if (itemToRemove != null) {
         // Delete materials before delete material group
         var materialsToRemove = DBBase.Context.Materials.Where(u => u.MaterialGroupID == itemToRemove.MaterialGroupID);
         DBBase.Context.Materials.RemoveRange(materialsToRemove);
         // Delete material group
         DBBase.Context.MaterialGroups.Remove(itemToRemove);
         DBBase.Context.SaveChanges();
         ret = true;
     }
     return ret;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Delete material operation
 /// </summary>
 /// <param name="Model">editor model(universal model for data exchange)</param>
 /// <returns>true- operation has done successful</returns>
 public bool DeleteMaterial(EditorModel Model)
 {
     bool ret = false;
     int DetectedMaterialGroup=DBBase.Context.MaterialGroups.SingleOrDefault(p=>p.Name==Model.SelectedMaterialGroup).MaterialGroupID;
     Materials foundedMaterial = DBBase.Context.Materials.SingleOrDefault(p => p.Name == Model.SelectedMaterial && p.MaterialGroupID == DetectedMaterialGroup);
     if (foundedMaterial != null) {
         DBBase.Context.Materials.Remove(foundedMaterial);
         DBBase.Context.SaveChanges();
     }
     return ret;
 }