public CommonResponse CancelCheckout(int id) { CommonResponse response = new CommonResponse(); try { Document document = repository.GetByID(id); if (document.CheckedoutByKey > 0 && LoggedUser.UserID != document.CheckedoutByKey && LoggedUser.Role != "Administrator") { document.CheckedoutBy = context.Set <User>().FirstOrDefault(u => u.UserKey == document.CheckedoutByKey); throw new KnownError(@"Error: Only User who Checked Out can ""Cancel Checked Out"": " + document.CheckedoutBy?.Value); } document.CheckedoutByKey = null; context.SaveChanges(); return(response.Success(_GetByID(id))); } catch (KnownError ke) { return(response.Error(ke)); } catch (Exception ex) { var originalException = GetOriginalException(ex); return(response.Error("Error " + originalException.Message)); } }
public CommonResponse Delete(cat_UserRole e) { CommonResponse response = new Reusable.CommonResponse(); if (e.UserRole != "" && e.UserRoleDesc != "") { using (CAPA_INVContext context = new CAPA_INVContext()) { cat_UserRole entity = context.cat_UserRole.FirstOrDefault(r => r.UserRoleKey == e.id); if (entity != null) { entity.UserRole = e.UserRole; entity.UserRoleDesc = e.UserRoleDesc; context.SaveChanges(); response.Success(entity, "OK"); return(response); } else { response.Error("User Role does not exist.", null); return(response); } } } else { response.Error("User Role or Description can not be empty.", null); return(response); } }
public CommonResponse ReadbyId(cat_UserRole e) { CommonResponse response = new Reusable.CommonResponse(); if (e.UserRoleKey > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { e = context.cat_UserRole.FirstOrDefault(r => r.UserRoleKey == e.id); if (e != null) { response.Success(e, "OK"); return(response); } else { response.Error("User Role ID was not found.", null); return(response); } } } else { response.Error("User Role ID can not be 0.", null); return(response); } }
public CommonResponse Create(cat_TicketType e) { CommonResponse response = new Reusable.CommonResponse(); if (e.TicketType != "" && e.TicketTypeDescirption != "") { using (CAPA_INVContext context = new CAPA_INVContext()) { if (context.cat_TicketType.FirstOrDefault(r => r.TicketTypeKey == e.id) == null) { context.cat_TicketType.Add(e); context.SaveChanges(); response.Success(e, "OK"); return(response); } else { response.Error("Ticket Category already exist.", null); return(response); } } } else { response.Error("Ticket Category or Description can not be empty.", null); return(response); } }
public CommonResponse Delete(cat_TicketType e) { CommonResponse response = new Reusable.CommonResponse(); if (e.id > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { cat_TicketType entity = context.cat_TicketType.FirstOrDefault(r => r.TicketTypeKey == e.id); if (entity != null) { context.cat_TicketType.Remove(entity); context.SaveChanges(); response.Success(); return(response); } else { response.Error("Ticket Type ID can not be find.", null); return(response); } } } response.Error("Ticket Type ID can not be 0.", null); return(response); }
public CommonResponse Delete(FS_ItemMaster e) { CommonResponse response = new Reusable.CommonResponse(); if (e.ItemNumber_FSKey > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { FS_ItemMaster entity = context.FS_ItemMaster.FirstOrDefault(r => r.ItemNumber_FSKey == e.ItemNumber_FSKey); if (entity != null) { context.FS_ItemMaster.Remove(entity); context.SaveChanges(); response.Success(); return(response); } else { response.Error("Item ID can not be find.", null); return(response); } } } response.Error("Item ID can not be 0.", null); return(response); }
public CommonResponse Delete(InventoryEvent e) { CommonResponse response = new Reusable.CommonResponse(); if (e.id > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { InventoryEvent entity = context.InventoryEvents.FirstOrDefault(r => r.InventoryEventKey == e.id); if (entity != null) { try { context.InventoryEvents.Remove(entity); context.SaveChanges(); response.Success(); return(response); }catch (Exception ex) { response.Error(ex.Message, null); return(response); } } else { response.Error("Inventory Event ID can not be find.", null); return(response); } } } response.Error("Inventory Event ID can not be 0.", null); return(response); }
public CommonResponse Create(MOTagCount e) { CommonResponse response = new Reusable.CommonResponse(); if (e.MOTagHeaderKey != 0 && e.Component_No != "" && e.Component_Desc != "") { using (CAPA_INVContext context = new CAPA_INVContext()) { if (context.MOTagHeaders.FirstOrDefault(r => (r.MOTagHeaderKey == e.MOTagHeaderKey)) != null) { context.MOTagCounts.Add(e); context.SaveChanges(); response.Success(e, "OK"); return(response); } else { response.Error("MO Tag Count already exist.", null); return(response); } } } else { response.Error("Component Name or Description can not be empty.", null); return(response); } }
public CommonResponse Delete(MOTagCount e) { CommonResponse response = new Reusable.CommonResponse(); if (e.MOTagHeaderKey > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { MOTagCount entity = context.MOTagCounts.FirstOrDefault(r => r.MOTagCountKey == e.MOTagCountKey); if (entity != null) { context.MOTagCounts.Remove(entity); context.SaveChanges(); response.Success(); return(response); } else { response.Error("MO Tag Line ID can not be find.", null); return(response); } } } response.Error("MO Tag Line ID can not be 0.", null); return(response); }
public CommonResponse Update(User e) { CommonResponse response = new Reusable.CommonResponse(); if (e.id > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { User entity = context.Users.FirstOrDefault(r => r.UserKey == e.id); if (entity != null) { entity.UserName = e.UserName; entity.UserRoleKey = e.UserRoleKey; entity.Password = e.Password; context.SaveChanges(); response.Success(entity, "OK"); return(response); } else { response.Error("User does not exist.", null); return(response); } } } else { response.Error("User Name or Description can not be empty.", null); return(response); } }
public CommonResponse Create(User e) { CommonResponse response = new Reusable.CommonResponse(); if (e.UserRoleKey != 0 && e.UserName.Length < 16) { using (CAPA_INVContext context = new CAPA_INVContext()) { if (context.Users.FirstOrDefault(r => (r.UserName == e.UserName)) == null) { e.UserName = e.UserName.ToUpper(); context.Users.Add(e); context.SaveChanges(); response.Success(e, "OK"); return(response); } else { response.Error("User already exist.", null); return(response); } } } else { response.Error("User Id can not be empty.", null); return(response); } }
public CommonResponse ReadByCounter(int Counter,int Event_ID) { CommonResponse response = new Reusable.CommonResponse(); Ticket e = new Ticket { TicketCounter = Counter, InventoryEventKey=Event_ID}; MOTagHeader MT = new MOTagHeader(); //e.TicketKey = ID; if (e.TicketCounter > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { e = context.Tickets.FirstOrDefault(r => (r.TicketCounter == e.TicketCounter && r.InventoryEventKey==e.InventoryEventKey)); MT = context.MOTagHeaders.FirstOrDefault(r => r.Ticket.TicketKey == e.TicketKey); if (MT != null) { response.Success(MT, "OK"); return response; } else { response.Error("MO Tag Counter was not found.", null); return response; } } } else { response.Error("MO Tag Counter can not be 0.", null); return response; } }
public CommonResponse Create(MOTagHeader e) { CommonResponse response = new Reusable.CommonResponse(); if (e.TicketKey != 0 && e.MO != "" && e.MO_Ln != "" && e.MO != null && e.MO_Ln != null) { using (CAPA_INVContext context = new CAPA_INVContext()) { if (context.MOTagHeaders.FirstOrDefault(r => (r.MO == e.MO && r.MO_Ln == e.MO_Ln)) == null) { context.MOTagHeaders.Add(e); context.SaveChanges(); response.Success(e, "OK"); return response; } else { response.Error("MO Tag Header already exist.", null); return response; } } } else { response.Error("Inventory Event Name or Description can not be empty.", null); return response; } }
public virtual CommonResponse Activate(int id) { CommonResponse response = new CommonResponse(); try { using (var transaction = context.Database.BeginTransaction()) { try { //repository.ByUserId = LoggedUser.UserID; repository.Activate(id); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); var originalException = GetOriginalException(e); return(response.Error("Error " + originalException.Message)); } } } catch (Exception e) { var originalException = GetOriginalException(e); return(response.Error("Error " + originalException.Message)); } return(response.Success(id)); }
public CommonResponse Delete(TicketCount e) { CommonResponse response = new Reusable.CommonResponse(); if (e.TicketKey > 0 && e.TagCountKey > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { TicketCount entity = context.TicketCounts.FirstOrDefault(r => (r.TicketKey == e.TicketKey && r.TagCountKey == e.TagCountKey)); if (entity != null) { context.TicketCounts.Remove(entity); context.SaveChanges(); response.Success(); return(response); } else { response.Error("Ticket ID can not be find.", null); return(response); } } } response.Error("Ticket ID can not be 0.", null); return(response); }
public CommonResponse Update(FSTI_Transactions e) { CommonResponse response = new Reusable.CommonResponse(); if (e.FSTI_Transaction_key > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { FSTI_Transactions entity = context.FSTI_Transactions.FirstOrDefault(r => r.FSTI_Transaction_key == e.FSTI_Transaction_key); if (entity != null) { entity.TransactionStringFields = e.TransactionStringFields; entity.TransactionProcessedYN = e.TransactionProcessedYN; entity.FSResponse = e.FSResponse; entity.FSError = e.FSError; entity.DateStampOut = e.DateStampOut; //entity.Password = e.Password; context.SaveChanges(); response.Success(entity, "OK"); return(response); } else { response.Error("FSTI Transaction does not exist.", null); return(response); } } } else { response.Error("FSTI Transaction key can not be empty.", null); return(response); } }
public CommonResponse Update(FS_ItemMaster e) { CommonResponse response = new Reusable.CommonResponse(); if (e.ItemNumber_FSKey > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { FS_ItemMaster entity = context.FS_ItemMaster.FirstOrDefault(r => r.ItemNumber_FSKey == e.ItemNumber_FSKey); if (entity != null) { //entity.UserName = e.UserName; //entity.UserRoleKey = e.UserRoleKey; //entity.Password = e.Password; //context.SaveChanges(); response.Success(entity, "OK"); return(response); } else { response.Error("Item does not exist.", null); return(response); } } } else { response.Error("Item can not be empty.", null); return(response); } }
public CommonResponse ReadbyId(int ID) { CommonResponse response = new Reusable.CommonResponse(); Ticket e = new Ticket { TicketKey = ID }; //e.TicketKey = ID; if (e.TicketKey > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { e = context.Tickets.FirstOrDefault(r => r.TicketKey == e.TicketKey); if (e != null) { response.Success(e, "OK"); return(response); } else { response.Error("Ticket ID was not found.", null); return(response); } } } else { response.Error("Ticket Type ID can not be 0.", null); return(response); } }
public CommonResponse Update(InventoryEvent e) { CommonResponse response = new Reusable.CommonResponse(); if (e.InventoryEventKey > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { InventoryEvent entity = context.InventoryEvents.FirstOrDefault(r => r.InventoryEventKey == e.InventoryEventKey); if (entity != null) { entity.InventoryEventName = e.InventoryEventName; entity.InventoryEventDescription = e.InventoryEventDescription; entity.Status = e.Status; entity.TicketCountTags = e.TicketCountTags; entity.MOTags = e.MOTags; context.SaveChanges(); response.Success(entity, "OK"); return(response); } else { response.Error("Inventory Event does not exist.", null); return(response); } } } else { response.Error("Inventory Event Name or Description can not be empty.", null); return(response); } }
}//by COUNTER public CommonResponse Update(Ticket e) { CommonResponse response = new Reusable.CommonResponse(); if (e.TicketKey != 0 && e.InventoryEventKey != 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { Ticket entity = context.Tickets.FirstOrDefault(r => r.TicketKey == e.TicketKey); if (entity != null) { entity = e; context.SaveChanges(); response.Success(entity, "OK"); return(response); } else { response.Error("Ticket does not exist.", null); return(response); } } } else { response.Error("Ticket Type or Description can not be empty.", null); return(response); } }
public CommonResponse Create(InventoryEvent e) { CommonResponse response = new Reusable.CommonResponse(); if (e.InventoryEventName != "" && e.InventoryEventName != "") { using (CAPA_INVContext context = new CAPA_INVContext()) { if (context.InventoryEvents.FirstOrDefault(r => r.InventoryEventName == e.InventoryEventName) == null) { context.InventoryEvents.Add(e); context.SaveChanges(); response.Success(e, "OK"); return(response); } else { response.Error("Inventory Event already exist.", null); return(response); } } } else { response.Error("Inventory Event Name or Description can not be empty.", null); return(response); } }
public CommonResponse GetbyTagNo(Ticket e) { CommonResponse response = new Reusable.CommonResponse(); //e.TicketKey = ID; if (e.TicketCounter > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { e = context.Tickets.FirstOrDefault(r => (r.TicketCounter == e.TicketCounter && r.InventoryEventKey == e.InventoryEventKey)); if (e != null) { response.Success(e, "OK"); return(response); } else { response.Error("Ticket ID was not found.", null); return(response); } } } else { response.Error("Ticket Type ID can not be 0.", null); return(response); } }
public CommonResponse Update(cat_TicketType e) { CommonResponse response = new Reusable.CommonResponse(); if (e.TicketType != "" && e.TicketTypeDescirption != "") { using (CAPA_INVContext context = new CAPA_INVContext()) { cat_TicketType entity = context.cat_TicketType.FirstOrDefault(r => r.TicketTypeKey == e.id); if (entity != null) { entity.TicketType = e.TicketType; entity.TicketTypeDescirption = e.TicketTypeDescirption; context.SaveChanges(); response.Success(entity, "OK"); return(response); } else { response.Error("Ticket Type does not exist.", null); return(response); } } } else { response.Error("Ticket Type or Description can not be empty.", null); return(response); } }
public CommonResponse Create(TicketCount e) { CommonResponse response = new Reusable.CommonResponse(); if (e.TicketKey != 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { if (context.TicketCounts.FirstOrDefault(r => (r.id == e.id)) == null) { context.TicketCounts.Add(e); context.SaveChanges(); response.Success(e, "OK"); return(response); } else { response.Error("Ticket Count already exist.", null); return(response); } } } else { response.Error("Ticket Id can not be empty.", null); return(response); } }
public CommonResponse AddCountTicket(Ticket e) { CommonResponse response = new Reusable.CommonResponse(); if (e.TicketCounter != 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { cat_TicketType _cat_TicketType = context.cat_TicketType.FirstOrDefault(r => r.TicketType == "TicketCount"); Ticket _Ticket = context.Tickets.FirstOrDefault(r => (r.TicketCounter == e.TicketCounter && r.InventoryEventKey == e.InventoryEventKey)); if (_Ticket == null) { _cat_TicketType.Tickets.Add(e); context.SaveChanges(); response.Success(e, "OK"); return(response); } else { response.Error("Ticket Category already exist.", null); return(response); } } } else { response.Error("Ticket Category or Description can not be empty.", null); return(response); } }
public CommonResponse ReadbyId(TicketCount e) { CommonResponse response = new Reusable.CommonResponse(); if (e.TicketKey > 0 && e.TagCountKey > 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { e = context.TicketCounts.FirstOrDefault(r => (r.TagCountKey == e.TagCountKey && r.Ticket.cat_TicketType.TicketType == "TicketCount")); if (e != null) { response.Success(e, "OK"); return(response); } else { response.Error("Ticket Count ID was not found.", null); return(response); } } } else { response.Error("Ticket Count ID can not be 0.", null); return(response); } }
public CommonResponse Create(cat_UserRole e) { CommonResponse response = new Reusable.CommonResponse(); if (e.UserRole != "" && e.UserRoleDesc != "") { using (CAPA_INVContext context = new CAPA_INVContext()) { if (context.cat_UserRole.FirstOrDefault(r => r.UserRole == e.UserRole) == null) { context.cat_UserRole.Add(e); context.SaveChanges(); response.Success(e, "OK"); return(response); } else { response.Error("User Role already exist.", null); return(response); } } } else { response.Error("User Role or Description can not be empty.", null); return(response); } }
}//by PN public CommonResponse Update(TicketCount e) { CommonResponse response = new Reusable.CommonResponse(); if (e.TicketKey != 0 && e.TagCountKey != 0) { using (CAPA_INVContext context = new CAPA_INVContext()) { TicketCount entity = context.TicketCounts.FirstOrDefault(r => (r.TicketKey == e.TicketKey && r.TagCountKey == e.TagCountKey)); if (entity != null) { UpdateEntity(ref entity, e); context.SaveChanges(); response.Success(entity, "OK"); return(response); } else { response.Error("Ticket does not exist.", null); return(response); } } } else { response.Error("Ticket can not be empty.", null); return(response); } }
public CommonResponse Checkout(int id) { CommonResponse response = new CommonResponse(); try { Document document = repository.GetByID(id); if (document.CheckedoutByKey == null) { document.CheckedoutByKey = LoggedUser.UserID; context.SaveChanges(); } else if (document.CheckedoutByKey > 0 && LoggedUser.UserID != document.CheckedoutByKey) { document.CheckedoutBy = context.Set <User>().FirstOrDefault(u => u.UserKey == document.CheckedoutByKey); throw new KnownError("Error: This document is already Checked Out by: " + document.CheckedoutBy?.Value); } return(response.Success(_GetByID(id))); } catch (KnownError ke) { return(response.Error(ke)); } catch (Exception ex) { var originalException = GetOriginalException(ex); return(response.Error("Error " + originalException.Message)); } }
public virtual CommonResponse AddToParent <ParentType>(int parentID, Entity entity) where ParentType : BaseEntity { CommonResponse response = new CommonResponse(); try { using (var transaction = context.Database.BeginTransaction()) { try { //var repository = RepositoryFactory.Create<Entity>(context, ByUserId); //var parentRepoType = typeof(BaseEntityRepository<>); //Type[] parentRepositoryArgs = { typeof(ParentType) }; //var makeme = parentRepoType.MakeGenericType(parentRepositoryArgs); //object parentRepository = Activator.CreateInstance(makeme); //PropertyInfo propContext = parentRepository.GetType().GetProperty("context", BindingFlags.Public | BindingFlags.Instance); //propContext.SetValue(parentRepository, context); //PropertyInfo propByUser = parentRepository.GetType().GetProperty("ByUserId", BindingFlags.Public | BindingFlags.Instance); //propByUser.SetValue(parentRepository, ByUserId); //MethodInfo method = parentRepository.GetType().GetMethod("GetByID"); //BaseEntity parent = (Entity)method.Invoke(parentRepository, new object[] { parentID }); //if (parent == null) //{ // return response.Error("Non-existent Parent Entity."); //} //repository.ByUserId = LoggedUser.UserID; ParentType parent = repository.AddToParent <ParentType>(parentID, entity); onAfterSaving(context, entity, parent, OPERATION_MODE.ADD); transaction.Commit(); } catch (KnownError error) { transaction.Rollback(); return(response.Error(error)); } catch (Exception e) { transaction.Rollback(); return(response.Error("ERROR: " + e.ToString())); } } } catch (KnownError error) { return(response.Error(error)); } catch (Exception e) { return(response.Error("ERROR: " + e.ToString())); } return(response.Success(entity)); }