예제 #1
0
        public JsonResult CheckDelete(IdeaModel model)
        {
            try
            {
                #region " [ Declaration ] "

                IdeaService _service = new IdeaService();

                #endregion

                #region " [ Main process ] "

                model.CreateBy = UserID;

                #endregion

                //Call to service
                return(this.Json(_service.CheckDelete(model), JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException serviceEx)
            {
                throw serviceEx;
            }
            catch (DataAccessException accessEx)
            {
                throw accessEx;
            }
            catch (Exception ex)
            {
                throw new ControllerException(FILE_NAME, "CheckDelete", UserID, ex);
            }
        }
예제 #2
0
        public JsonResult Edit(IdeaModel model)
        {
            try
            {
                #region " [ Declaration ] "

                IdeaService _service = new IdeaService();

                #endregion

                #region " [ Main processing ] "

                model.CreateBy   = UserID;
                model.UpdateBy   = UserID;
                model.CreateDate = DateTime.Now;
                model.UpdateDate = DateTime.Now;

                #endregion

                // Call to service
                return(this.Json(_service.Save(model), JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException serviceEx)
            {
                throw serviceEx;
            }
            catch (DataAccessException accessEx)
            {
                throw accessEx;
            }
            catch (Exception ex)
            {
                throw new ControllerException(FILE_NAME, "Edit", UserID, ex);
            }
        }
예제 #3
0
        public ActionResult Edit(string id)
        {
            try
            {
                #region " [ Declaration ] "

                IdeaService _service = new IdeaService();

                ViewBag.id = id;

                #endregion

                // Call to service
                IdeaModel model = _service.GetItemByID(new IdeaModel()
                {
                    ID = new Guid(id), CreateBy = UserID, Insert = false
                });

                return(View(model));
            }
            catch (ServiceException serviceEx)
            {
                throw serviceEx;
            }
            catch (DataAccessException accessEx)
            {
                throw accessEx;
            }
            catch (Exception ex)
            {
                throw new ControllerException(FILE_NAME, "Edit", UserID, ex);
            }
        }
예제 #4
0
        public ActionResult Create()
        {
            try
            {
                #region " [ Declaration ] "

                IdeaModel model = new IdeaModel()
                {
                    ID       = Guid.NewGuid(),
                    CreateBy = UserID,
                    Insert   = true
                };

                #endregion

                return(View(model));
            }
            catch (ServiceException serviceEx)
            {
                throw serviceEx;
            }
            catch (DataAccessException accessEx)
            {
                throw accessEx;
            }
            catch (Exception ex)
            {
                throw new ControllerException(FILE_NAME, "Create", UserID, ex);
            }
        }
예제 #5
0
 /// <summary>
 /// Get item
 /// </summary>
 /// <param name="model">Idea model</param>
 /// <returns>IdeaModel</returns>
 public IdeaModel GetItemByID(IdeaModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             PN_IDEA _md = context.PN_IDEA.FirstOrDefault(m => m.id == model.ID && m.created_by == model.CreateBy && !m.deleted);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "GetItemByID", model.CreateBy);
             }
             return(new IdeaModel()
             {
                 ID = _md.id,
                 Title = _md.title,
                 Content = _md.content
             });
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "GetItemByID", model.CreateBy, ex);
     }
 }
예제 #6
0
 /// <summary>
 /// Delete
 /// </summary>
 /// <param name="model">Idea model</param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper Delete(IdeaModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             PN_IDEA _md = context.PN_IDEA.FirstOrDefault(m => m.id == model.ID && m.created_by == model.CreateBy && !m.deleted);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "Delete", model.CreateBy);
             }
             _md.deleted      = true;
             _md.deleted_by   = model.DeleteBy;
             _md.deleted_date = DateTime.Now;
             context.PN_IDEA.Attach(_md);
             context.Entry(_md).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "Delete", model.CreateBy, ex);
     }
     Notifier.Notification(model.CreateBy, Message.DeleteSuccess, Notifier.TYPE.Success);
     return(ResponseStatusCodeHelper.Success);
 }
예제 #7
0
 /// <summary>
 /// Save
 /// </summary>
 /// <param name="model">Idea model</param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper Save(IdeaModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             PN_IDEA _md = new PN_IDEA();
             if (model.Insert)
             {
                 _md.id = Guid.NewGuid();
             }
             else
             {
                 _md = context.PN_IDEA.FirstOrDefault(m => m.id == model.ID && !m.deleted);
                 if (_md == null)
                 {
                     throw new DataAccessException(FILE_NAME, "Save", model.CreateBy);
                 }
             }
             _md.title   = model.Title;
             _md.content = model.Content;
             if (model.Insert)
             {
                 _md.created_by   = model.CreateBy;
                 _md.created_date = DateTime.Now;
                 context.PN_IDEA.Add(_md);
                 context.Entry(_md).State = EntityState.Added;
             }
             else
             {
                 _md.updated_by   = model.UpdateBy;
                 _md.updated_date = DateTime.Now;
                 context.PN_IDEA.Attach(_md);
                 context.Entry(_md).State = EntityState.Modified;
             }
             context.SaveChanges();
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "Save", model.CreateBy, ex);
     }
     if (model.Insert)
     {
         Notifier.Notification(model.CreateBy, Message.InsertSuccess, Notifier.TYPE.Success);
     }
     else
     {
         Notifier.Notification(model.CreateBy, Message.UpdateSuccess, Notifier.TYPE.Success);
     }
     return(ResponseStatusCodeHelper.Success);
 }
예제 #8
0
        public IActionResult Index()
        {
            IdeaModel modelio = new IdeaModel();

            modelio.Users     = db.Users.ToList();
            modelio.Units     = db.Units.ToList();
            modelio.Divisions = db.Divisions.ToList();

            return(View("~/NewIdea/NewIdea.cshtml", modelio));
        }
예제 #9
0
        protected override void LoadFileContent()
        {
            foreach (XElement element in XDocument.Load(filePath).Element("Root").Element("Ideas").Elements("Idea"))
            {
                IdeaModel ideaModel = new IdeaModel();
                ideaModel.Title   = element.Attribute("title").Value;
                ideaModel.Url     = element.Attribute("url").Value;
                ideaModel.Content = element.Attribute("content").Value;

                ideaModels.Add(ideaModel);
            }
        }
예제 #10
0
        public async Task <IActionResult> Put(string id, [FromBody] IdeaModel value)
        {
            var idea = await GetIdeaById(id);

            if (idea == null)
            {
                return(NotFound());
            }

            idea.content    = value.content;
            idea.impact     = value.impact;
            idea.ease       = value.ease;
            idea.confidence = value.confidence;

            await _repository.UpdateAsync(idea);

            return(Ok(idea));
        }
예제 #11
0
 /// <summary>
 /// Check Delete item
 /// </summary>
 /// <param name="model">Idea model</param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper CheckDelete(IdeaModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             PN_TARGET _md = context.PN_TARGET.FirstOrDefault(m => m.idea_id == model.ID && !m.deleted && m.created_by == model.CreateBy);
             if (_md == null)
             {
                 return(ResponseStatusCodeHelper.OK);
             }
         }
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "CheckDelete", model.CreateBy, ex);
     }
     return(ResponseStatusCodeHelper.NG);
 }
예제 #12
0
        public IActionResult Index(string filter)
        {
            IdeaModel modelio = new IdeaModel();

            modelio.Users     = db.Users.ToList();
            modelio.Units     = db.Units.ToList();
            modelio.Divisions = db.Divisions.ToList();
            modelio.Ideas     = db.Ideas.Include(i => i.IdeaUpdoots).Include(i => i.EIdeasUser).ToList();

            if (filter != "Null")
            {
                switch (filter)
                {
                case "TopIdeas":
                    modelio.Ideas = modelio.Ideas.OrderByDescending(a => a.IdeaUpdoots.Count()).ToList();
                    break;

                case "LatestIdeas":
                    modelio.Ideas = modelio.Ideas.OrderByDescending(a => a.CreatedDate).ToList();
                    break;

                case "PDCAIdeas":
                    modelio.Ideas = modelio.Ideas.OrderByDescending(a => a.PDCA).ToList();
                    break;

                case "DivisionIdeas":
                    modelio.Ideas = modelio.Ideas.OrderBy(a => a.EIdeasUser.UserDivision.DivisionName).ToList();
                    break;

                case "UnitIdeas":
                    modelio.Ideas = modelio.Ideas.OrderBy(a => a.EIdeasUser.UserUnit.UnitName).ToList();
                    break;

                default:
                    break;
                }
            }


            return(View("~/Ideas/Ideas.cshtml", modelio));
        }
예제 #13
0
        public async Task <IActionResult> Post([FromBody] IdeaModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var idea = new Idea
            {
                id         = Guid.NewGuid().ToString("n").Substring(0, 8),
                idUsers    = (await Functions.GetCurrentUser(HttpContext, _userRepository)).id,
                content    = value.content,
                impact     = value.impact,
                ease       = value.ease,
                confidence = value.confidence,
                created_at = DateTime.UtcNow
            };

            await _repository.InsertAsync(idea);

            return(Created($"ideas/{idea.id}", idea));
        }
예제 #14
0
        public ActionResult Create(IdeaModel model, string deleteIdeaImage)
        {
            IdeaRepository objidea = new IdeaRepository(this.SessionCustom);

            try
            {
                this.SessionCustom.Begin();

                objidea.Entity = model.Idea;
                if (!string.IsNullOrEmpty(deleteIdeaImage))
                {
                    objidea.Entity.Image = null;
                }

                objidea.Update();
                this.InsertAudit("Update", this.Module.Name + " -> " + model.Idea.IdeaId);

                this.SessionCustom.Commit();
            }
            catch (Exception ex)
            {
                SessionCustom.RollBack();
                Utils.InsertLog(
                    this.SessionCustom,
                    "Error" + this.Module.Name,
                    ex.Message + " " + ex.StackTrace);
            }

            if (Request.Form["GetOut"] == "0")
            {
                return(this.RedirectToAction("Index", "Idea"));
            }
            else
            {
                return(this.RedirectToAction("Detail", "Idea", new { mod = Module.ModulId, id = objidea.Entity.IdeaId }));
            }
        }
예제 #15
0
        public async Task Post_ShouldInsertIdea()
        {
            var idea = new IdeaModel
            {
                content    = "My idea",
                impact     = 6,
                ease       = 7,
                confidence = 8
            };

            // Arrange
            Functions.AddMockIdentityToContext(_ideasController, "*****@*****.**");

            // Act
            var result = await _ideasController.Post(idea);

            // Assert
            Assert.NotNull(result);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.Equal(201, createdResult.StatusCode);
        }
예제 #16
0
        public async Task Put_ShouldUpdateIdea()
        {
            var idea = new IdeaModel
            {
                content    = "Idea 2 edited",
                impact     = 6,
                ease       = 7,
                confidence = 8
            };

            // Arrange
            Functions.AddMockIdentityToContext(_ideasController, "*****@*****.**");

            // Act
            var result = await _ideasController.Put("ghijkl", idea);

            // Assert
            Assert.NotNull(result);

            var okResult = result as OkObjectResult;

            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
        }
예제 #17
0
        public async Task <bool> findClassAndStoreAsync()
        {
            switch (storeClass)
            {
            //Task - Need To Listify
            case "Account":
                AccountModel         accountModelManager = new AccountModel(attribute, record);
                Repository <Account> repo = new Repository <Account>();
                var DatabaseAccounts      = await repo.AllAsync();

                var Matches = DatabaseAccounts.Where(a => a.Url == accountModelManager.account.Url).ToList();

                if (Matches.Count() == 0)
                {
                    int completedCount = await repo.InsertAsync(accountModelManager.account);

                    if (completedCount != 0)
                    {
                        System.Diagnostics.Debug.WriteLine(completedCount + "Account records inserted");
                    }
                }
                else
                {
                    int UpdatedCount = await repo.UpdateAsync(accountModelManager.account);

                    if (UpdatedCount != 0)
                    {
                        System.Diagnostics.Debug.WriteLine(UpdatedCount + "Account records Updated");
                    }
                }
                break;

            case "Users__c":

                UserModel         userModelManager = new UserModel(attribute, record);
                Repository <User> UserRepo         = new Repository <User>();
                var DatabaseUsers = await UserRepo.AllAsync();

                var UserMatches = DatabaseUsers.Where(a => a.Url == userModelManager.user.Url).ToList();

                if (UserMatches.Count() == 0)
                {
                    int completedCount = await UserRepo.InsertAsync(userModelManager.user);

                    if (completedCount != 0)
                    {
                        System.Diagnostics.Debug.WriteLine(completedCount + "user records inserted");
                    }
                }
                else
                {
                    int UpdatedCount = await UserRepo.UpdateAsync(userModelManager.user);

                    if (UpdatedCount != 0)
                    {
                        System.Diagnostics.Debug.WriteLine(UpdatedCount + "user records Updated");
                    }
                }

                break;

            case "Events__c":

                EventsModel         eventsModelManager = new EventsModel(attribute, record);
                Repository <Events> EventsRepo         = new Repository <Events>();
                var DatabaseEvents = await EventsRepo.AllAsync();

                var EventMatches = DatabaseEvents.Where(a => a.url == eventsModelManager.events.url).ToList();

                if (EventMatches.Count() == 0)
                {
                    int completedCount = await EventsRepo.InsertAsync(eventsModelManager.events);

                    if (completedCount != 0)
                    {
                        System.Diagnostics.Debug.WriteLine(completedCount + "event records inserted");
                    }
                }
                else
                {
                    int UpdatedCount = await EventsRepo.UpdateAsync(eventsModelManager.events);

                    if (UpdatedCount != 0)
                    {
                        System.Diagnostics.Debug.WriteLine(UpdatedCount + "event records Updated");
                    }
                }


                break;

            case "Idea__c":

                IdeaModel         IdeaModelManager = new IdeaModel(attribute, record);
                Repository <Idea> IdeaRepo         = new Repository <Idea>();
                var DatabaseIdea = await IdeaRepo.AllAsync();

                var IdeaMatches = DatabaseIdea.Where(a => a.url == IdeaModelManager.idea.url).ToList();

                if (IdeaMatches.Count() == 0)
                {
                    int completedCount = await IdeaRepo.InsertAsync(IdeaModelManager.idea);

                    if (completedCount != 0)
                    {
                        System.Diagnostics.Debug.WriteLine(completedCount + "event records inserted");
                    }
                }
                else
                {
                    int UpdatedCount = await IdeaRepo.UpdateAsync(IdeaModelManager.idea);

                    if (UpdatedCount != 0)
                    {
                        System.Diagnostics.Debug.WriteLine(UpdatedCount + "event records Updated");
                    }
                }

                break;
            }
            return(true);
        }
예제 #18
0
 public static Idea ToEntity(this IdeaModel model, Idea destination)
 {
     return(model.MapTo(destination));
 }
예제 #19
0
 public static Idea ToEntity(this IdeaModel model)
 {
     return(model.MapTo <IdeaModel, Idea>());
 }