public static string GenerateTrackingNo(string ownerShip, int div, bool isSystem, DateTime purchaseDate) { PapayaEntities db = new PapayaEntities(); string ret = ""; //Always get the FIRST character of the Ownership ret = string.Format("{0}{1}", ret, ownerShip.Substring(0, 1)); //Append Division No ret = string.Format("{0}{1}", ret, div.ToString()); //Append System ret = string.Format("{0}{1}", ret, (isSystem ? "S" : "N")); //Search for running no from db with same purchase date int count = db.rs_assets.Where(x => x.PurchaseDate == purchaseDate && x.rs_ownership.OwnerType == ownerShip && x.rs_division.DivisionNo == div).Count() + 1; //Append Purchase date ret = string.Format("{0}-{1}", ret, purchaseDate.ToString("MMyy")); //Append Running No ret = string.Format("{0}-{1}", ret, count.ToString("0000")); return(ret); }
public static SystemBookData GetSystemBookModel(int id) { PapayaEntities db = new PapayaEntities(); SystemBookData model = new SystemBookData(); rs_assets system = db.rs_assets.Where(x => x.AssetId == id).SingleOrDefault(); //AssetId must be unique if (system != null) { if (system.IsSystem) { List <SystemAsset> assets = new List <SystemAsset>(); List <rs_assets_rel> relations = db.rs_assets_rel.Where(x => x.SysId == id).ToList(); foreach (rs_assets_rel rel in relations) { SystemAsset asset = new SystemAsset(); asset.SubAsset = rel.rs_assets; if (rel.rs_assets.Availability == 1) { asset.IsSelected = true; } assets.Add(asset); } model.Assets = assets; } model.System = system; } return(model); }
public static bool hasAccess(IPrincipal user, string action, string controller) { PapayaEntities db = new PapayaEntities(); if (user.Identity.Name.Equals("papaya")) { return(true); } else { int groupId = (user.Identity is FormsIdentity) ? int.Parse(((FormsIdentity)user.Identity).Ticket.UserData) : 0; rs_useracl acl = db.rs_useracl.FirstOrDefault(e => e.GroupId == groupId && e.rs_action.Name == action && e.FlagActive == true && e.rs_action.rs_module.Controller == controller); if (acl == null) { return(false); } else { return(true); } } }
public static List <string> GetBookedDates(int AssetId) { PapayaEntities db = new PapayaEntities(); List <string> ret = new List <string>(); List <rs_bookings> bookings = db.rs_bookings.Where(x => x.AssetId == AssetId && !x.Returned).ToList(); foreach (rs_bookings book in bookings) { for (DateTime date = book.StartDate; date.Date <= book.EndDate.Date; date = date.AddDays(1)) { string dateStr = date.ToString("d-M-yyyy"); ret.Add(dateStr); } } return(ret); }
public void Log(string operation, string description) { PapayaEntities db = new PapayaEntities(); rs_syslog syslog = new rs_syslog(); syslog.Action = Action; syslog.Controller = Controller; syslog.Operation = operation; syslog.Description = description; syslog.User = Username; syslog.ClientIP = ClientIP; syslog.LogTime = DateTime.Now; db.rs_syslog.Add(syslog); db.SaveChanges(); }
/* * Function to populate the system model and related assets into a list */ public static SystemModel GetSystemModel(int id) { PapayaEntities db = new PapayaEntities(); SystemModel model = new SystemModel(); rs_assets system = db.rs_assets.Where(x => x.AssetId == id).SingleOrDefault(); //AssetId must be unique if (system != null) { if (system.IsSystem) { List <rs_assets> assets = new List <rs_assets>(); List <rs_assets_rel> relations = db.rs_assets_rel.Where(x => x.SysId == id).ToList(); foreach (rs_assets_rel rel in relations) { assets.Add(rel.rs_assets); } model.Assets = assets; } model.System = system; } return(model); }
public static bool IsAdmin(string username) { PapayaEntities db = new PapayaEntities(); return(db.rs_user.FirstOrDefault(e => e.Username == username).rs_user_group.Name.ToLower().Contains("admin")); }
public static int GetUserId(string username) { PapayaEntities db = new PapayaEntities(); return(db.rs_user.FirstOrDefault(e => e.Username == username).UserId); }