All Kode .net
Simple Crud .net
https://phpsance.blogspot.com/p/all-kode-updatedeleteinsertselect-simple.html
Catatan 8Elements
.net core and mvc... web
Datashowtime = database
Repository = koneksi database(DC)
halamn
https://localhost:44335/Rest/GetAllPageText?lang=en&page=1&pageSize=20
repositori
GetAllPageText
Repositori.cs
public static List<PageText> GetAllPageText(string lang)
=>Connect to database
RestContoller.cs
public ActionResult GetAllPageText(string lang)
pagination L1
https://codewithmukesh.com/blog/pagination-in-aspnet-core-webapi/
L2
https://www.mikesdotnetting.com/article/328/simple-paging-in-asp-net-core-razor-pages
========================
RestController
public ActionResult GetAllPageText(string lang, int startIndex = 0, int pageSize = 10)
{
try
{
var json = JsonConvert.SerializeObject(Repositories.GetAllPageText(lang, startIndex, pageSize));
return Content(json);
}
catch (Exception e)
{
return Content(e.Message);
}
}
Repositori
public static List<PageText> GetAllPageText(string lang,int startIndex = 0, int pageSize = 10)
{
using (var dc = new ShowtimeEntities())
{
if (!string.IsNullOrEmpty(lang))
{
return dc.PageTexts.Where(pt => pt.LanguageCode == lang).OrderByDescending(pt => pt.Id).Skip(startIndex * pageSize).Take(pageSize).ToList();
}
return dc.PageTexts.OrderByDescending(pt => pt.Id).Skip(startIndex * pageSize).Take(pageSize).ToList();
}
}
?startinde00=1&ennd=10
table addeventvote
contoh
AddOrUpdatePromotion
Repositories.cs
public static Promotion AddOrUpdatePromotion(Promotion promotion)
{
using (var dc = new ShowtimeEntities())
{
var promotionExt = dc.Promotions.SingleOrDefault(p => p.Id == promotion.Id);
if (promotionExt == null) {
dc.Promotions.Add(promotion);
dc.SaveChanges();
return promotion;
}
PromotionHistory promotionHistory = new PromotionHistory()
{
PromotionId = promotionExt.Id,
Rules = promotionExt.Rules,
StartDate = promotionExt.StartDate,
EndDate = promotionExt.EndDate,
Disabled = promotionExt.Disabled,
Pause = promotionExt.Pause,
CreateDate = DateTime.Now
};
promotionExt.Rules = promotion?.Rules ?? promotionExt.Rules;
promotionExt.StartDate = promotion?.StartDate ?? promotionExt.StartDate;
promotionExt.EndDate = promotion?.EndDate ?? promotionExt.EndDate;
promotionExt.Disabled = promotion?.Disabled ?? promotionExt.Disabled;
promotionExt.Pause = promotion?.Pause ?? promotionExt.Pause;
promotionExt.UpdateDate = DateTime.Now;
dc.PromotionHistories.Add(promotionHistory);
dc.SaveChanges();
return promotionExt;
}
}
RestContoller.cs
public ActionResult AddPromotion([FromBody]PromotionModel value)
{
var startDate = DateTime.Parse(value.StartDate + " " + value.StartTime);
var endDate = DateTime.Parse(value.EndDate + " " + value.EndTime);
var check = Repositories.GetPromotionByTimeRange(startDate, endDate,value.Id);
if (check != null)
{
return Content("There's an event on that time");
}
Promotion promotion = new Promotion()
{
Id = value.Id,
EventId = value.EventId,
StartDate = startDate,
EndDate = endDate,
Rules = value.Rules,
Pause = false,
Disabled = false,
CreateDate = DateTime.Now
};
Repositories.AddOrUpdatePromotion(promotion);
return Content("ok");
}
===================
Halaman Pagging Start
===================
RestController.cs
public ActionResult GetAllPageText(string lang, int startIndex = 0, int pageSize = 10)
{
try
{
var json = JsonConvert.SerializeObject(Repositories.GetAllPageText(lang, startIndex, pageSize));
return Content(json);
}
catch (Exception e)
{
return Content(e.Message);
}
}
*************
Repositories.cs
*************
public static List<PageText> GetAllPageText(string lang,int startIndex = 0, int pageSize = 10)
{
using (var dc = new ShowtimeEntities())
{
if (!string.IsNullOrEmpty(lang))
{
return dc.PageTexts.Where(pt => pt.LanguageCode == lang).OrderByDescending(pt => pt.Id).Skip(startIndex * pageSize).Take(pageSize).ToList();
}
return dc.PageTexts.OrderByDescending(pt => pt.Id).Skip(startIndex * pageSize).Take(pageSize).ToList();
}
}
===================
Halaman pagging End
===================
===================
Tambah Data Start
===================
RestController.cs
[System.Web.Mvc.HttpPost]
public ActionResult AddEventVote([FromBody] EventVoteModel value)
{
EventVote EvVote = new EventVote()
{
Id = value.Id,
CreateDate= DateTime.Now,
UserId = value.UserID,
EventParticipantId = value.EventParticipantID,
Reference = value.Reference,
Status = value.status,
StatusMessage = value.StatusMessage,
Amount = value.Amount,
EventId = value.EventID,
TotalVote = value.TotalVote,
PromotionId = value.PromotionID
};
Repositories.AddEventVote(EvVote);
return Content("ok");
}
*****************
EventVoteModel.cs
*****************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EightElements.Showtime.CMS.Web.Models
{
public class EventVoteModel
{
public int Id { set; get; }
public string CreateDate { set; get; }
public int UserID { set; get; }
public int EventParticipantID { set; get; }
public string Reference { set; get; }
public int status { set; get; }
public string StatusMessage { set; get; }
public int Amount { set; get; }
public int EventID { set; get;}
public int TotalVote { set; get; }
public int PromotionID { set; get; }
}
}
*****************
Repositories.cs
*****************
public static EventVote AddEventVote(EventVote Evote)
{
using (var dc = new ShowtimeEntities())
{
var EventVoteExt = dc.EventVotes.SingleOrDefault(p => p.Id == Evote.Id);
if (EventVoteExt == null)
{
dc.EventVotes.Add(Evote);
dc.SaveChanges();
return Evote;
}
return EventVoteExt;
}
}
===================
Tambah Data End
===================
192.168.110.31
sance
pwd:Sance*8e
===================
Tambah Data Start V1
===================
RestController.cs
[System.Web.Mvc.HttpPost]
public ActionResult AddActionTracking([FromBody] ActionTrackingModel value)
{
ActionTracking BB = new ActionTracking()
{
RefererUrl = value.RefererUrl,
RequestUrl = value.RequestUrl,
UserId = value.UserId,
CreateDate = DateTime.Now,
Remarks = value.Remarks,
TrackingType = value.TrackingType,
TrafficSource = value.TrafficSource,
Campaign = value.Campaign,
PubId = value.PubId,
LandingPage = value.LandingPage,
GeolocationId = value.GeolocationId,
TrackingCookieId = value.TrackingCookieId
};
Repositories.AddActionTracking(BB);
return Content("ok");
}
********
Repositories.cs
********
public static ActionTracking AddActionTracking(ActionTracking BB)
{
using (var dc = new ShowtimeEntities())
{
var ret = dc.ActionTrackings.SingleOrDefault(p => p.Id == BB.Id);
if (ret == null)
{
dc.ActionTrackings.Add(BB);
dc.SaveChanges();
return BB;
}
return ret;
}
}
******
ActionTrackingModel.cs
*******
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EightElements.Showtime.CMS.Web.Models
{
public class ActionTrackingModel
{
public int Id { get; set; }
public string RefererUrl { get; set; }
public string RequestUrl { get; set; }
public int UserId { get; set; }
public string Remarks { get; set; }
public int TrackingType { get; set; }
public string TrafficSource { get; set; }
public string Campaign { get; set; }
public string PubId { get; set; }
public string LandingPage { get; set; }
public int GeolocationId { get; set; }
public int TrackingCookieId { get; set; }
}
}
=====================================
No comments