/// <summary> /// Add Ticket with receive (class)message /// </summary> /// <returns>true or false</returns> private bool TicketAdd() { using (TicketSoftjournContext myDatabase = new TicketSoftjournContext()) { try { Entity.Ticket ticketDb = new Entity.Ticket { Id = Id, Number = Number, Description = Description, TicketTypeId = (int)TicketTypeId, ExpiryDateTime = ExpiryDateTime }; myDatabase.Ticket.Add(ticketDb); myDatabase.SaveChanges(); return(true); } catch { return(false); } } }
/// <summary> /// Add tags's ticket /// </summary> /// <returns>true or false</returns> private bool TicketAddTags() { using (TicketSoftjournContext myDatabase = new TicketSoftjournContext()) { try { for (int i = 0; i < Tags.Count(); i++) { var selectId = myDatabase.TicketToTags.Select(x => x.Id).FirstOrDefault(); int newId = (selectId == 0) ? 1 : myDatabase.TicketToTags.OrderByDescending(x => x.Id).Select(x => x.Id).First() + 1;; TicketToTags tagsDb = new TicketToTags { Id = newId, TicketId = Id, TagId = Tags[i] }; myDatabase.TicketToTags.Add(tagsDb); myDatabase.SaveChanges(); } return(true); } catch { return(false); } } }
/// <summary> /// Tag's add /// </summary> /// <param name="addTag">String Tag</param> /// <returns>int: new id tag or error -1</returns> private int TagsAdd(string addTag) { using (TicketSoftjournContext myDatabase = new TicketSoftjournContext()) { var tag = myDatabase.TicketTags.Where(t => t.TagTitle.ToLower() == addTag.ToLower()).FirstOrDefault(); if (tag != null) { //if exists return(tag.TagId); } else { try { int newId; var selectId = myDatabase.TicketTags.Select(x => x.TagId).FirstOrDefault(); //if exists = db query+1, else 1 newId = (selectId == 0) ? 1 : myDatabase.TicketTags.OrderByDescending(x => x.TagId).Select(x => x.TagId).First() + 1; //add tag TicketTags tagDb = new TicketTags { TagId = newId, TagTitle = addTag.ToLower() }; myDatabase.TicketTags.Add(tagDb); myDatabase.SaveChanges(); return(newId); } catch { //error returns -1 return(-1); } } } }