コード例 #1
0
        public override CommonResponse <TicketStatusVM> DeleteData(TicketStatusVM data, string transactionId)
        {
            IQueryable <TicketStatus> lastDataContext = DbContext.TicketStatuses.AsQueryable();

            if (string.IsNullOrEmpty(data?.Id))
            {
                return(new CommonResponse <TicketStatusVM>
                {
                    Status = false,
                    Code = "E-001",
                    Message = "Please fill the ID!",
                    Data = new TicketStatusVM[] { data },
                });
            }

            lastDataContext = lastDataContext.Where(u =>
                                                    u.Id.Equals(data.Id)
                                                    );

            TicketStatus lastData = lastDataContext.FirstOrDefault();

            int historySequence = lastData.TicketStatusHistories
                                  .Select(u => u.Seq)
                                  .OrderByDescending(u => u)
                                  .FirstOrDefault();

            lastData.IsDeleted = true;

            TicketStatusHistory ticketStatusHistory = new TicketStatusHistory();

            ticketStatusHistory.FillFromTicketStatus(
                lastData,
                transactionId,
                historySequence + 1,
                TableTransactionOperation.Update
                );

            DbContext.Add(ticketStatusHistory);

            if (DbContext.SaveChanges() > 0)
            {
                return(new CommonResponse <TicketStatusVM>
                {
                    Status = true,
                    Code = "S",
                    Message = "Delete Data is Success!",
                    Data = new TicketStatusVM[] { data },
                });
            }
            else
            {
                return(new CommonResponse <TicketStatusVM>
                {
                    Status = false,
                    Code = "E-003",
                    Message = "Delete Data Failed! Please Contact an Web Administrator!",
                    Data = new TicketStatusVM[] { data },
                });
            }
        }
コード例 #2
0
        public override CommonResponse <TicketStatusVM> SaveData(TicketStatusVM data, string transactionId)
        {
            CommonResponse <TicketStatusVM> response = ValidateParameter(data);

            if (response != null)
            {
                return(response);
            }

            string lastId = DbContext.TicketStatuses.Select(u => u.Id).OrderByDescending(u => u).FirstOrDefault();

            TicketStatus ticketStatusData = new TicketStatus
            {
                Id   = CreateNewTicketStatusId(lastId),
                Name = data?.Name,
            };

            DbContext.Add(ticketStatusData);

            TicketStatusHistory ticketStatusHistory = new TicketStatusHistory();

            ticketStatusHistory.FillFromTicketStatus(
                ticketStatusData,
                transactionId,
                1,
                TableTransactionOperation.Insert
                );

            DbContext.Add(ticketStatusHistory);

            if (DbContext.SaveChanges() > 0)
            {
                data.Id = ticketStatusData.Id;

                return(new CommonResponse <TicketStatusVM>
                {
                    Status = true,
                    Code = "S",
                    Message = "Retrieve Data is Success!",
                    Data = new TicketStatusVM[] { data },
                });
            }
            else
            {
                return(new CommonResponse <TicketStatusVM>
                {
                    Status = false,
                    Code = "E-003",
                    Message = "Save Data Failed! Please Contact an Web Administrator!",
                    Data = new TicketStatusVM[] { data },
                });
            }
        }