コード例 #1
0
        /// <summary>
        /// D01 save db
        /// </summary>
        /// <param name="dataModel"></param>
        /// <returns></returns>
        public MSGReturnModel saveD01(D01ViewModel dataModel)
        {
            MSGReturnModel result = new MSGReturnModel();

            try
            {
                if (dataModel.ActionType == "Add")
                {
                    if (db.Flow_Info.Where(x => x.PRJID == dataModel.PRJID && x.FLOWID == dataModel.FLOWID).Count() > 0)
                    {
                        result.RETURN_FLAG = false;
                        result.DESCRIPTION = "資料重複:" + dataModel.PRJID + " " + dataModel.FLOWID + " 已存在";
                        return(result);
                    }

                    db.Flow_Info.Add(
                        new Flow_Info()
                    {
                        PRJID              = dataModel.PRJID,
                        FLOWID             = dataModel.FLOWID,
                        Group_Product_Code = dataModel.Group_Product_Code,
                        Publish_Date       = DateTime.Parse(dataModel.Publish_Date),
                        Apply_On_Date      = DateTime.Parse(dataModel.Apply_On_Date),
                        Apply_Off_Date     = DateTime.Parse(dataModel.Apply_Off_Date),
                        Issuer             = dataModel.Issuer,
                        Memo = dataModel.Memo
                    });
                }
                else if (dataModel.ActionType == "Modify")
                {
                    Flow_Info oldData = db.Flow_Info.Where(x => x.PRJID == dataModel.PRJID && x.FLOWID == dataModel.FLOWID).FirstOrDefault();
                    oldData.PRJID              = dataModel.PRJID;
                    oldData.FLOWID             = dataModel.FLOWID;
                    oldData.Group_Product_Code = dataModel.Group_Product_Code;
                    oldData.Publish_Date       = DateTime.Parse(dataModel.Publish_Date);
                    oldData.Apply_On_Date      = DateTime.Parse(dataModel.Apply_On_Date);
                    oldData.Apply_Off_Date     = DateTime.Parse(dataModel.Apply_Off_Date);
                    oldData.Issuer             = dataModel.Issuer;
                    oldData.Memo = dataModel.Memo;
                }

                db.SaveChanges(); //Save
                result.RETURN_FLAG = true;
            }
            catch (DbUpdateException ex)
            {
                result.RETURN_FLAG = false;
                result.DESCRIPTION = Message_Type
                                     .save_Fail.GetDescription("D01",
                                                               $"message: {ex.Message}" +
                                                               $", inner message {ex.InnerException?.InnerException?.Message}");
            }

            return(result);
        }
コード例 #2
0
 /// <summary>
 /// Db 組成 D01ViewModel
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 private D01ViewModel DbToD01ViewModel(Flow_Info data)
 {
     return(new D01ViewModel()
     {
         PRJID = data.PRJID,
         FLOWID = data.FLOWID,
         Group_Product_Code = data.Group_Product_Code,
         Publish_Date = TypeTransfer.dateTimeNToString(data.Publish_Date),
         Apply_On_Date = TypeTransfer.dateTimeNToString(data.Apply_On_Date),
         Apply_Off_Date = TypeTransfer.dateTimeNToString(data.Apply_Off_Date),
         Issuer = data.Issuer,
         Memo = data.Memo
     });
 }