/// <summary> /// Get bulletin details for specified ID. /// </summary> /// <param name="bulletinID">The bulletin ID.</param> /// <returns>The bulletin details.</returns> public BulletinModel Get(int bulletinID) { var key = new KeyModel(CacheType.Global, "BulletinItem").Add(bulletinID); BulletinModel data = null; if (!CacheService.TryGet(key, out data)) { var sqlParameters = new List <SqlParameter>(); sqlParameters.Add(new SqlParameter { ParameterName = "@SiteId", SqlDbType = SqlDbType.VarChar, Value = SiteID }); sqlParameters.Add(new SqlParameter { ParameterName = "@PageId", SqlDbType = SqlDbType.Int, Value = bulletinID }); data = SqlService.Execute <BulletinModel>(connectionName, "AjsCmsPageGet", sqlParameters, reader => { var contentPage = new BulletinModel(); contentPage.Url = reader.GetString(0).ToLower(); contentPage.Title = reader.GetString(1); contentPage.PageId = reader.GetInt32(2); contentPage.Html = reader[10] as string; contentPage.HtmlExtended = reader[11] as string; contentPage.ExtensionData = reader[12] as string; contentPage.ExtensionType = reader[13] as string; contentPage.LiveDate = reader.GetDateTime(15); if (!string.IsNullOrEmpty(contentPage.ExtensionData) && contentPage.ExtensionType == "BULLETIN") { contentPage.BulletinContracts = Deserialize <BulletinExtensionData>(contentPage.ExtensionData).Contracts; } else { return(null); } return(contentPage); } ).FirstOrDefault(); if (data == null) { throw new DataException(String.Format("Bulletin data is not available for the bulletin code - {0}", bulletinID)); } data.Html = ReplaceContent(data.Html); data.HtmlExtended = ReplaceContent(data.HtmlExtended); CacheService.Set(key, data, defaultTimeSpan); } if (data == null) { throw new DataException(String.Format("Bulletin data is not available for the bulletin code - {0}", bulletinID)); } return(data); }
public async Task <Response <BulletinModel> > GetSpecificBulletin(string bulletin_idx) { string apiName = "GET SPECIFIC BULLETIN"; BulletinBadResponse bulletinBadResponse = delegate(ConTextColor preColor, int status, ConTextColor setColor, string msg) { BulletinModel tempModel = new BulletinModel(); ServiceManager.ShowRequestResult(apiName, preColor, status, setColor); return(new Response <BulletinModel> { data = tempModel, message = msg, status = status }); }; if (ComDef.jwtService.IsTokenValid(ServiceManager.GetHeaderValue(WebOperationContext.Current))) { try { BulletinModel bulletin = new BulletinModel(); using (IDbConnection db = GetConnection()) { db.Open(); string selectSql = $@" SELECT * FROM bulletin_tb WHERE idx = '{bulletin_idx}' "; bulletin = await bulletinDBManager.GetSingleDataAsync(db, selectSql, ""); if (bulletin != null) { ServiceManager.ShowRequestResult(apiName, ConTextColor.LIGHT_GREEN, ResponseStatus.OK, ConTextColor.WHITE); return(new Response <BulletinModel> { data = bulletin, message = ResponseMessage.OK, status = ResponseStatus.OK }); } else { return(bulletinBadResponse(ConTextColor.RED, ResponseStatus.NOT_FOUND, ConTextColor.WHITE, "게시글이 존재하지 않습니다.")); } } } catch (Exception e) { Console.WriteLine(apiName + " ERROR : " + e.Message); return(bulletinBadResponse(ConTextColor.PURPLE, ResponseStatus.INTERNAL_SERVER_ERROR, ConTextColor.WHITE, ResponseMessage.INTERNAL_SERVER_ERROR)); } } else { return(bulletinBadResponse(ConTextColor.RED, ResponseStatus.BAD_REQUEST, ConTextColor.WHITE, ResponseMessage.BAD_REQUEST)); } }
public ActionResult SaveBulletin(BulletinModel objBulletinModel, HttpPostedFileBase fileUpload) { try { if (fileUpload != null) { string fileName = string.Empty; string destinationPath = string.Empty; fileName = Path.GetFileName(fileUpload.FileName); string AttachmentType = Path.GetExtension(fileUpload.FileName); Stream fs = fileUpload.InputStream; BinaryReader br = new BinaryReader(fs); byte[] bytes = br.ReadBytes((Int32)fs.Length); string ImageContent = Convert.ToBase64String(bytes); objBulletinModel.AttachmentContent = bytes; objBulletinModel.AttachmentName = fileName; objBulletinModel.AttachmentSize = fs.Length; objBulletinModel.AttachmentType = AttachmentType; } objBulletinModel.IsActive = true; objBulletinModel.CreatedBy = LoggedInUserID; ; //Insert or Update Bulletin serviceResponse = objUtilityWeb.PostAsJsonAsync(WebApiURL.Bulletin + "/InsertUpdateBulletin", objBulletinModel); objBulletinModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <BulletinModel>().Result : null; //if error code is 0 means Bulletin saved successfully if (Convert.ToInt32(objBulletinModel.ErrorCode) == 0) { // Set success message TempData["SucessMessage"] = "Bulletin Saved Successfully"; return(RedirectToAction("ViewBulletin", "Bulletin")); } else if (Convert.ToInt32(objBulletinModel.ErrorCode) == 52) { //If Errorcode is 52 means Bulletin Name is duplicate set duplicate Bulletin error message. objBulletinModel.Message = "Bulletin Duplicate not allowed"; objBulletinModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower(); } else { //set Error Message if error code is greater than 0 but not 52 (duplicate) objBulletinModel.Message = "Error while adding record"; objBulletinModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower(); } } catch (Exception ex) { ErrorLog(ex, "Bulletin", "SaveBulletin POST"); } return(View("SaveBulletin", objBulletinModel)); }
/// <summary> /// Get Bulletin By Id /// </summary> /// <param name="BulletinId"></param> /// <returns>Bulletin Model</returns> public BulletinModel GetBulletinById(int BulletinId) { //Call GetBulletinBYId method of dataLayer which will return Datatable. DataTable dt = objDLBulletin.GetBulletinById(BulletinId); BulletinModel objBulletinModel = new BulletinModel(); // if datatable has row than set object parameters if (dt.Rows.Count > 0) { objBulletinModel = GetDataRowToEntity <BulletinModel>(dt.Rows[0]); } return(objBulletinModel); }
/// <summary> /// Map between the Bulletin Domain Models and the Bulletin View Models. /// </summary> public static BulletinViewModel ToBulletinViewModel(this BulletinModel src) { var dest = new BulletinViewModel(); dest.BulletinContracts = src.BulletinContracts; //dest.ExpiresDate = src.ExpiresDate; dest.Html = src.Html; dest.HtmlExtended = src.HtmlExtended; dest.LiveDate = src.LiveDate; dest.PageId = src.PageId; dest.Title = src.Title; dest.Url = src.Url; return(dest); // Domain Model to View Model //mapper.CreateMap<BulletinModel, BulletinViewModel>(); }
/// <summary> /// Get Bulletin List based on paging, searching and sorting parameter /// </summary> /// <param name="objViewBulletinModel">object of Model ViewBulletinModel</param> /// <returns></returns> public ViewBulletinModel GetBulletinList(ViewBulletinModel objViewBulletinModel) { List <BulletinModel> lstBulletinModel = new List <BulletinModel>(); //if FilterBulletinName is NULL than set to empty objViewBulletinModel.FilterBulletinName = objViewBulletinModel.FilterBulletinName ?? String.Empty; //if SortBy is NULL than set to empty objViewBulletinModel.SortBy = objViewBulletinModel.SortBy ?? String.Empty; //call GetBulletinList Method which will retrun datatable of Bulletin DataTable dtBulletin = objDLBulletin.GetBulletinList(objViewBulletinModel); //fetch each row of datable foreach (DataRow dr in dtBulletin.Rows) { //Convert datarow into Model object and set Model object property BulletinModel itemBulletinModel = GetDataRowToEntity <BulletinModel>(dr); //Add Bulletin in List lstBulletinModel.Add(itemBulletinModel); } //set Bulletin List of Model ViewBulletinModel objViewBulletinModel.BulletinList = lstBulletinModel; //if Bulletin List count is not null and greater than 0 Than set Total Pages for Paging. if (objViewBulletinModel != null && objViewBulletinModel.BulletinList != null && objViewBulletinModel.BulletinList.Count > 0) { objViewBulletinModel.CurrentPage = objViewBulletinModel.BulletinList[0].CurrentPage; int totalRecord = objViewBulletinModel.BulletinList[0].TotalCount; if (decimal.Remainder(totalRecord, objViewBulletinModel.PageSize) > 0) { objViewBulletinModel.TotalPages = (totalRecord / objViewBulletinModel.PageSize + 1); } else { objViewBulletinModel.TotalPages = totalRecord / objViewBulletinModel.PageSize; } } else { objViewBulletinModel.TotalPages = 0; objViewBulletinModel.CurrentPage = 1; } return(objViewBulletinModel); }
public ActionResult Download(string DocID) { HttpResponseMessage serviceResponse; UtilityWeb objUtilityWeb = new UtilityWeb(); BulletinModel objBulletinModel = new BulletinModel(); serviceResponse = objUtilityWeb.GetAsync(WebApiURL.Bulletin + "/GetBulletinById?BulletinId=" + DocID.ToString()); objBulletinModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <BulletinModel>().Result : null; Response.Clear(); MemoryStream ms = new MemoryStream(objBulletinModel.AttachmentContent); Response.ContentType = objBulletinModel.AttachmentType; Response.AddHeader("content-disposition", objBulletinModel.AttachmentType); Response.Buffer = true; ms.WriteTo(Response.OutputStream); Response.End(); return(new FileStreamResult(ms, objBulletinModel.AttachmentType)); }
public ActionResult ActivateDeactivateBulletin(string prm = "") { BulletinModel objBulletinModel = new BulletinModel(); try { //if prm(Paramter) is empty means Add condition else edit condition if (!String.IsNullOrEmpty(prm)) { int BulletinId; int Status; //decrypt parameter and set in BulletinId variable int.TryParse(CommonUtils.Decrypt(prm.Split('~')[0]), out BulletinId); int.TryParse(prm.Split('~')[1], out Status); //Get Bulletin detail by Bulletin Id serviceResponse = objUtilityWeb.GetAsync(WebApiURL.Bulletin + "/UpdateBulletinStatusByID?BulletinId=" + BulletinId.ToString() + "&status=" + Status); objBulletinModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <BulletinModel>().Result : null; //serviceResponse = objUtilityWeb.GetAsync(WebApiURL.UserLogin + "/GetUserListById?UserId=" + UserId.ToString()); //objUserLogin = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync<UserLogin>().Result : null; //if (objUserLogin != null) //{ // serviceResponse = objUtilityWeb.GetAsync(WebApiURL.UserLogin + "/UpdateUserStatusByID?UserId=" + BulletinId.ToString() + "&status=" + Status); // objUserLogin = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync<UserLogin>().Result : null; // //Admin_UpdateUserStatusByID //} } } catch (Exception ex) { ErrorLog(ex, "Bulletin", "ViewBulletin"); } return(RedirectToAction("ViewBulletin")); }
/// <summary> /// Insert or Update Bulletin /// </summary> /// <param name="objBulletinModel"></param> /// <returns></returns> public BulletinModel InsertUpdateBulletin(BulletinModel objBulletinModel) { try { objBulletinModel.BulletinName = objBulletinModel.BulletinName.ToString().Trim(); int ErrorCode = 0; string ErrorMessage = ""; SqlParameter pErrorCode = new SqlParameter("@ErrorCode", ErrorCode); pErrorCode.Direction = ParameterDirection.Output; SqlParameter pErrorMessage = new SqlParameter("@ErrorMessage", ErrorMessage); pErrorMessage.Direction = ParameterDirection.Output; SqlParameter[] parmList = { new SqlParameter("@BulletinID", objBulletinModel.BulletinID) , new SqlParameter("@BulletinName", objBulletinModel.BulletinName) , new SqlParameter("@Description", objBulletinModel.Description) , new SqlParameter("@ClassName", objBulletinModel.ClassName) , new SqlParameter("@AttachmentID", objBulletinModel.AttachmentID) , new SqlParameter("@AttachmentType", objBulletinModel.AttachmentType) , new SqlParameter("@AttachmentName", objBulletinModel.AttachmentName) , new SqlParameter("@AttachmentSize", objBulletinModel.AttachmentSize) , new SqlParameter("@AttachmentContent", objBulletinModel.AttachmentContent) , new SqlParameter("@IsActive", objBulletinModel.IsActive) , new SqlParameter("@CreatedBy", objBulletinModel.CreatedBy) , pErrorCode , pErrorMessage }; //If BulletinId is 0 Than Insert Bulletin else Update Bulletin SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, DBConstants.Admin_InsertUpdateBulletin, parmList); //set error code and message objBulletinModel.ErrorCode = Convert.ToInt32(pErrorCode.Value); objBulletinModel.Message = Convert.ToString(pErrorMessage.Value); return(objBulletinModel); } catch (Exception ex) { throw ex; } }
public ActionResult SaveBulletin(string prm = "") { BulletinModel objBulletinModel = new BulletinModel(); try { //if prm(Paramter) is empty means Add condition else edit condition if (!String.IsNullOrEmpty(prm)) { int BulletinId; //decrypt parameter and set in BulletinId variable int.TryParse(CommonUtils.Decrypt(prm), out BulletinId); //Get Bulletin detail by Bulletin Id serviceResponse = objUtilityWeb.GetAsync(WebApiURL.Bulletin + "/GetBulletinById?BulletinId=" + BulletinId.ToString()); objBulletinModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <BulletinModel>().Result : null; } } catch (Exception ex) { ErrorLog(ex, "Bulletin", "SaveBulletin Get"); } return(View("SaveBulletin", objBulletinModel)); }
/// <summary> /// Get all bulletins of the specified type. /// </summary> /// <param name="bulletinType">The bulletin type.</param> /// <param name="limit">The maximum number of bulletins to get.</param> /// <returns>Bulletins of the specified type.</returns> public IList <BulletinModel> List(BulletinType bulletinType, int limit) { var key = new KeyModel(CacheType.Global, "BulletinList"); IList <BulletinModel> data; if (!CacheService.TryGet(key, out data)) { var sqlParameters = new List <SqlParameter> { new SqlParameter { ParameterName = "@SiteId", SqlDbType = SqlDbType.VarChar, Value = SiteID } }; var bulletinList = SqlService.Execute <BulletinModel>(connectionName, "AjsCmsPageGetAll", sqlParameters, reader => { var contentPage = new BulletinModel(); contentPage.Url = reader.GetString(0).ToLower(); contentPage.Title = reader.GetString(1); contentPage.PageId = reader.GetInt32(2); contentPage.ExtensionType = reader[10] as string; contentPage.LiveDate = reader.GetDateTime(12); contentPage.ExtensionData = reader[14] as string; return(contentPage); } ).ToList(); foreach (var bulletin in bulletinList) { if (bulletin.ExtensionType == "BULLETIN" && !string.IsNullOrEmpty(bulletin.ExtensionData)) { var contractData = Deserialize <BulletinExtensionData>(bulletin.ExtensionData); bulletin.BulletinContracts = contractData != null ? contractData.Contracts : null; } } data = bulletinList.OrderByDescending(b => b.LiveDate).ToList(); if (data.Any()) { CacheService.Set(key, data, defaultTimeSpan); } } // Filter by contract data = data.AsParallel().Where(b => b.BulletinContracts != null && b.BulletinContracts.Any(c => c.Equals(bulletinType.ToString(), StringComparison.OrdinalIgnoreCase))).ToList(); // Then apply limit if (limit > 0) { data = data.Take(limit).ToList(); } return(data); }
public async Task <Response> WriteBulletin(string title, string content, string writer, string category) { string apiName = "WRITE BULLETIN"; if (ComDef.jwtService.IsTokenValid(ServiceManager.GetHeaderValue(WebOperationContext.Current))) { var writeArgs = ComUtil.GetStringLengths(title, content, writer, category); if (title != null && content != null && writer != null && category != null && writeArgs[0] > 0 && writeArgs[1] > 0 && writeArgs[2] > 0 && writeArgs[3] > 0) { try { using (IDbConnection db = GetConnection()) { db.Open(); var model = new BulletinModel(); model.title = title; model.content = content; model.writer = writer; model.category = category; string insertSql = @" INSERT INTO bulletin_tb( title, content, writer, category ) VALUES( @title, @content, @writer, @category );"; if (await bulletinDBManager.InsertAsync(db, insertSql, model) == QueryExecutionResult.SUCCESS) { // await bulletinDBManager.IndexSortSqlAsync(db, ServiceManager.GetIndexSortSQL("bulletin_idx", "bulletin_tb")); return(ServiceManager.Result(apiName, ResponseType.CREATED)); } else { return(ServiceManager.Result(apiName, ResponseType.BAD_REQUEST)); } } } catch (Exception e) { Console.WriteLine(apiName + " ERROR : " + e.Message); return(ServiceManager.Result(apiName, ResponseType.INTERNAL_SERVER_ERROR)); } } else { return(ServiceManager.Result(apiName, ResponseType.BAD_REQUEST)); } } else { return(ServiceManager.Result(apiName, ResponseType.BAD_REQUEST)); } }
public async Task <Response> PutBulletin(string title, string content, string writer, string category, int bulletin_idx) { string apiName = "PUT BULLETIN"; if (ComDef.jwtService.IsTokenValid(ServiceManager.GetHeaderValue(WebOperationContext.Current))) { var putArgs = ComUtil.GetStringLengths(title, content, writer); if (title != null && content != null && writer != null && category != null && putArgs[0] > 0 && putArgs[1] > 0 && putArgs[2] > 0 && bulletin_idx.ToString().Length > 0) { try { using (IDbConnection db = GetConnection()) { db.Open(); var model = new BulletinModel(); model.title = title; model.content = content; model.writer = writer; model.bulletin_idx = bulletin_idx; model.category = category; string updateSql = $@" UPDATE bulletin_tb SET title = '{title}', content = '{content}', category = '{category}' WHERE writer = '{writer}' AND idx = '{bulletin_idx}' ;"; if (await bulletinDBManager.UpdateAsync(db, updateSql, model) == QueryExecutionResult.SUCCESS) { // await bulletinDBManager.IndexSortSqlAsync(db, updateSql); return(ServiceManager.Result(apiName, ResponseType.OK)); } else { return(ServiceManager.Result(apiName, ResponseType.BAD_REQUEST)); } } } catch (Exception e) { Console.WriteLine(apiName + " ERROR : " + e.Message); return(ServiceManager.Result(apiName, ResponseType.INTERNAL_SERVER_ERROR)); } } else { return(ServiceManager.Result(apiName, ResponseType.BAD_REQUEST)); } } else { return(ServiceManager.Result(apiName, ResponseType.BAD_REQUEST)); } }
public async Task <Response> DeleteBulletin(string writer, int bulletin_idx) { string apiName = "DELETE BULLETIN"; if (ComDef.jwtService.IsTokenValid(ServiceManager.GetHeaderValue(WebOperationContext.Current))) { if (bulletin_idx.ToString() != null && bulletin_idx.ToString().Length > 0 && writer != null && writer.Trim().Length > 0) { try { using (IDbConnection db = GetConnection()) { db.Open(); var model = new BulletinModel(); model.bulletin_idx = bulletin_idx; model.writer = writer; string deleteBulletinSql = $@" DELETE FROM bulletin_tb WHERE writer = '{writer}' AND bulletin_idx = '{bulletin_idx}' ;"; string selectCommentSql = $@" SELECT * FROM comment_tb WHERE bulletin_idx = '{bulletin_idx}' "; string deleteCommentSql = $@" DELETE FROM comment_tb WHERE bulletin_idx = '{bulletin_idx}' ;"; if (await bulletinDBManager.DeleteAsync(db, deleteBulletinSql, model) == QueryExecutionResult.SUCCESS) { var commentItems = await commentDBManager.GetListAsync(db, selectCommentSql, ""); if (commentItems.Count > 0) { for (int i = 0; i < commentItems.Count; i++) { await commentDBManager.DeleteAsync(db, deleteCommentSql, commentItems[i]); } } // await bulletinDBManager.IndexSortSqlAsync(db, ServiceManager.GetIndexSortSQL("bulletin_idx", "bulletin_tb")); return(ServiceManager.Result(apiName, ResponseType.OK)); } else { return(ServiceManager.Result(apiName, ResponseType.BAD_REQUEST)); } } } catch (Exception e) { Console.WriteLine(apiName + " ERROR : " + e.Message); return(ServiceManager.Result(apiName, ResponseType.INTERNAL_SERVER_ERROR)); } } else { return(ServiceManager.Result(apiName, ResponseType.BAD_REQUEST)); } } else { return(ServiceManager.Result(apiName, ResponseType.BAD_REQUEST)); } }
public BulletinModel InsertUpdateBulletin(BulletinModel objBulletinModel) { return(objBLBulletin.InsertUpdateBulletin(objBulletinModel)); }
/// <summary> /// Insert or Update Bulletin /// </summary> /// <param name="objBulletinModel">object of Bulletin Model</param> /// <param name="ErrorCode"></param> /// <param name="ErrorMessage"></param> /// <returns></returns> public BulletinModel InsertUpdateBulletin(BulletinModel objBulletinModel) { //call InsertUpdateBulletin Method of dataLayer and return BulletinModel return(objDLBulletin.InsertUpdateBulletin(objBulletinModel)); }