public object DeleteCustomer(int CustomerID) { object result = null; int message = 0; using (_ctx = new ApiSecurityEntities()) { using (var _ctxTransaction = _ctx.Database.BeginTransaction()) { try { var idToRemove = _ctx.Customers.SingleOrDefault(x => x.CustomerID == CustomerID); if (idToRemove != null) { _ctx.Customers.Remove(idToRemove); _ctx.SaveChanges(); } _ctxTransaction.Commit(); message = (int)responseMessage.Success; } catch (Exception e) { _ctxTransaction.Rollback(); e.ToString(); message = (int)responseMessage.Error; } result = new { message }; } } return(result); }
public object UpdateCustomer(Customer model) { object result = null; int message = 0; using (_ctx = new ApiSecurityEntities()) { using (var _ctxTransaction = _ctx.Database.BeginTransaction()) { try { var idToUpdate = _ctx.Customers.SingleOrDefault(x => x.CustomerID == model.CustomerID); if (idToUpdate != null) { _ctx.Entry(idToUpdate).CurrentValues.SetValues(model); _ctx.SaveChanges(); } _ctxTransaction.Commit(); message = (int)responseMessage.Success; } catch (Exception e) { _ctxTransaction.Rollback(); e.ToString(); message = (int)responseMessage.Error; } result = new { message }; } } return(result); }
public object SaveCustomer(Customer model) { object result = null; int message = 0; using (_ctx = new ApiSecurityEntities()) { using (var _ctxTransaction = _ctx.Database.BeginTransaction()) { try { _ctx.Customers.Add(model); _ctx.SaveChanges(); _ctxTransaction.Commit(); message = (int)responseMessage.Success; } catch (Exception e) { _ctxTransaction.Rollback(); e.ToString(); message = (int)responseMessage.Error; } result = new { message }; } } return(result); }
public loggedUserModel MemberAuthentication(loginUserModel model) { loggedUserModel UserAuth = null; if (model != null) { using (_ctx = new ApiSecurityEntities()) { UserAuth = ( from u in _ctx.UserAuthentications join r in _ctx.UserRoles on u.RoleID equals r.RoleID where u.LoginID == model.LoginId && u.Password == model.Password && u.StatusID == 1 select new { UserId = u.UserID, UserName = u.UserName, Role = r.RoleName, Status = (int)u.StatusID }).Select(x => new loggedUserModel { UserId = x.UserId, UserName = x.UserName, Role = x.Role, Status = (int)x.Status }).FirstOrDefault(); } } return(UserAuth); }
public object GetCustomer(int pageNumber, int pageSize) { object result = null; using (_ctx = new ApiSecurityEntities()) { result = new { recordsTotal = _ctx.Customers.Count(), customer = _ctx.Customers.OrderBy(i => i.CustomerID).Skip(pageNumber).Take(pageSize).ToList() }; } return(result); }
public bool ValidateAuthorization(string userid, string methodtype) { bool IsValid = false; if (userid != null) { using (_ctx = new ApiSecurityEntities()) { if (_ctx.UserAuthentications.Any(u => u.LoginID == userid && u.StatusID == 1)) { switch (methodtype) { case "get": IsValid = (from u in _ctx.UserAuthentications join r in _ctx.UserRoles on u.RoleID equals r.RoleID where u.LoginID == userid && u.StatusID == 1 && r.CanRead == true select u).Any(); break; case "post": IsValid = (from u in _ctx.UserAuthentications join r in _ctx.UserRoles on u.RoleID equals r.RoleID where u.LoginID == userid && u.StatusID == 1 && r.CanCreate == true select u).Any(); break; case "put": IsValid = (from u in _ctx.UserAuthentications join r in _ctx.UserRoles on u.RoleID equals r.RoleID where u.LoginID == userid && u.StatusID == 1 && r.CanUpdate == true select u).Any(); break; case "delete": IsValid = (from u in _ctx.UserAuthentications join r in _ctx.UserRoles on u.RoleID equals r.RoleID where u.LoginID == userid && u.StatusID == 1 && r.CanDelete == true select u).Any(); break; default: IsValid = false; break; } } } } return(IsValid); }