public ActionResult EditComment(string id) { LETTERS_COMMENT_DATA letter = (LETTERS_COMMENT_DATA)StrawmanDBLibray.DBLibrary.GetCommentsById(id); Models.FormUtilModel.TextArea model = new Models.FormUtilModel.TextArea { id = "comment", comment = letter.COMMENT, data_attributes = "edit", letter_id = letter.LETTER_ID.ToString(), comment_id = id, source = letter.TYPE }; if (letter != null) { switch (letter.TYPE) { default: MANAGEMENT_LETTERS_REL rel = (MANAGEMENT_LETTERS_REL)StrawmanDBLibray.DBLibrary.GetMasterRelByLetterId(letter.LETTER_ID.ToString()); MANAGEMENT_LETTERS_MASTER master = (MANAGEMENT_LETTERS_MASTER)StrawmanDBLibray.DBLibrary.GetCommentsMasterById(letter.LETTER_ID.ToString()); model.letter_id = letter.ID.ToString(); model.market = rel.MARKET.ToString(); model.brand = rel.BRAND.ToString(); model.channel = rel.CHANNEL.ToString(); model.name = master.NAME; break; case Entities.CommentTypes.MANAGEMENT_LETTER: case Entities.CommentTypes.MONTHLY_COMMENTS: model.name = letter.TYPE; break; } } return(PartialView(NEW_COMMENT, model)); }
public ActionResult InsertComment(Models.FormUtilModel.TextArea data) { if (Helpers.UserUtils.UserName == null) { Response.Redirect("~/Account/LogIn?returnUrl="); } int result = 0; string type = string.IsNullOrEmpty(data.comment) || data.comment.Trim().Length == 0?"delete":data.data_attributes; string source = data.source; switch (type) { case "new": //insertar el nuevo comment //EntityCollection<LETTERS_COMMENT_DATA> letters = new EntityCollection<LETTERS_COMMENT_DATA>(); //MANAGEMENT_LETTERS_MASTER master = null; //MANAGEMENT_LETTERS_REL rel = null; //if (data["comment_id"] != null) //{ // rel = (MANAGEMENT_LETTERS_REL)StrawmanDBLibray.DBLibrary.GetMasterRelById(data["comment_id"]); // master = (MANAGEMENT_LETTERS_MASTER)StrawmanDBLibray.DBLibrary.GetCommentsMasterById(rel.MANAGEMENT_LETTER_ID.ToString()); // List<LETTERS_COMMENT_DATA> letters_tmp = (List<LETTERS_COMMENT_DATA>)StrawmanDBLibray.DBLibrary.GetCommentsByMasterId(master.ID.ToString()); // letters_tmp.ForEach(letters.A);// (EntityCollection<LETTERS_COMMENT_DATA>)StrawmanDBLibray.DBLibrary.GetCommentsByMasterId(master.ID.ToString()); //} switch (source) { default: //Comentario LETTERS_COMMENT_DATA letter = new LETTERS_COMMENT_DATA { COMMENT = data.comment, USER = Helpers.UserUtils.UserName, YEAR_PERIOD = Helpers.PeriodUtil.Year, MONTH_PERIOD = Helpers.PeriodUtil.Month, TYPE = COMMENT_TYPE, DATE = DateTime.Now, }; //Maestro Letters MANAGEMENT_LETTERS_MASTER master = new MANAGEMENT_LETTERS_MASTER { COUNTRY = Helpers.CountryUtil.Country, NAME = data.name, CHANNEL = decimal.Parse(data.channel.ToString()), CHANNEL_GROUP = decimal.Parse(data.channel.ToString()), }; //Relacción Maestro Letters - Commentario MANAGEMENT_LETTERS_REL rel = new MANAGEMENT_LETTERS_REL { ID = data.comment_id != null?decimal.Parse(data.comment_id.ToString()) : 0, CHANNEL = decimal.Parse(data.channel.ToString()), BRAND = decimal.Parse(data.brand.ToString()), MARKET = decimal.Parse(data.market.ToString()), }; decimal tmp_group; MANAGEMENT_LETTERS_MASTER_REL msrel = new MANAGEMENT_LETTERS_MASTER_REL { CHANNEL = decimal.Parse(data.channel.ToString()), BRAND = decimal.Parse(data.brand.ToString()), MARKET = decimal.Parse(data.market.ToString()), GROUP = decimal.TryParse(data.group, out tmp_group)? tmp_group: default(decimal?) }; result = StrawmanDBLibray.DBLibrary.SaveComment(letter, master, rel, msrel); break; case Entities.CommentTypes.MANAGEMENT_LETTER: //Relación Maestro BOY-Maestro Letters MANAGEMENT_LETTERS_MASTER_REL ms_rel = ((List <StrawmanDBLibray.Entities.MANAGEMENT_LETTERS_MASTER_REL>)Helpers.StrawmanDBLibrayData.Get(StrawmanDataTables.MANAGEMENT_LETTERS_MASTER_REL)) .Where(m => m.MASTER_ID == decimal.Parse(data.letter_id.ToString())).FirstOrDefault(); //Relación Maestro Letters - Comentario MANAGEMENT_LETTERS_REL m_rel = new MANAGEMENT_LETTERS_REL { ID = data.letter_id != null?decimal.Parse(data.letter_id.ToString()) : 0, CHANNEL = (decimal)ms_rel.CHANNEL, BRAND = (decimal)ms_rel.BRAND, MARKET = (decimal)ms_rel.MARKET, }; //Comentario LETTERS_COMMENT_DATA m_letter = new LETTERS_COMMENT_DATA { LETTER_ID = decimal.Parse(data.letter_id), COMMENT = data.comment, USER = Helpers.UserUtils.UserName, YEAR_PERIOD = Helpers.PeriodUtil.Year, MONTH_PERIOD = Helpers.PeriodUtil.Month, TYPE = source, DATE = DateTime.Now, }; result = StrawmanDBLibray.DBLibrary.SaveComment(m_letter, null, m_rel, ms_rel); break; } break; case "delete": case "edit": //editar comment por id if (data.letter_id != null) { string _id = data.letter_id; switch (source) { case Entities.CommentTypes.MONTHLY_COMMENTS: case Entities.CommentTypes.MANAGEMENT_LETTER: _id = data.comment_id; break; } LETTERS_COMMENT_DATA letter_ed = (LETTERS_COMMENT_DATA)StrawmanDBLibray.DBLibrary.GetCommentsById(_id); if (type == "edit") { letter_ed.COMMENT = data.comment; letter_ed.DATE = DateTime.Now; result = StrawmanDBLibray.DBLibrary.SaveCommentData(StrawmanDataTables.LETTERS_COMMENT_DATA, letter_ed); } else { result = StrawmanDBLibray.DBLibrary.RemoveComment(StrawmanDataTables.LETTERS_COMMENT_DATA, letter_ed); } } break; } return(new JsonResult() { Data = new { Success = true, Result = result } }); }