public void ForeignKeyExceptionIsRecognized1()
        {
            // --- Arrange
            var parent = new ParentRecord
            {
                Name = "Parent",
            };
            var child = new ChildRecord
            {
                Name     = "Child1",
                Value    = 1,
                ParentId = -1
            };

            // --- Act
            ForeignKeyViolationException exCaught = null;

            try
            {
                using (var ctx = DataAccessFactory.CreateContext <ITestDataOperations>())
                {
                    ctx.InsertParent(parent, false);
                    ctx.InsertChild(child);
                }
            }
            catch (ForeignKeyViolationException ex)
            {
                exCaught = ex;
            }

            // --- Assert
            // ReSharper disable once PossibleNullReferenceException
            exCaught.KeyName.ShouldEqual("FK_Child_ToParent");
        }
예제 #2
0
        public ShellViewModel()
        {
            DisplayName = Assembly.GetExecutingAssembly().GetName().Name;

            var items = new List <DomainRecord>();

            var father = new ParentRecord {
                Id = 999, Name = "Big Daddy"
            };
            var mother = new ParentRecord {
                Id = 1001, Name = "Little Momma"
            };

            items.Add(new DomainRecord {
                Name = "First", Parent = father, State = StateEnum.Default
            });
            items.Add(new DomainRecord {
                Name = "Second", Parent = mother, State = StateEnum.Default
            });

            _detail = new DomainRecordDetailViewModel();
            _detail.Parents.AddRange(new[] { father, mother }.Select(p => new NameWrapper <ParentRecord>(p.Name, p)));

            _master = new DomainRecordMasterViewModel(items, _detail);
        }
        public void PrimaryKeyExceptionIsRecognized()
        {
            // --- Arrange
            var parent = new ParentRecord
            {
                Name = "Parent"
            };

            // --- Act
            PrimaryKeyViolationException exCaught = null;

            try
            {
                using (var ctx = DataAccessFactory.CreateContext <ITestDataOperations>())
                {
                    ctx.InsertParent(parent, false);
                    ctx.InsertParent(parent, true);
                }
            }
            catch (PrimaryKeyViolationException ex)
            {
                exCaught = ex;
            }

            // --- Assert
            // ReSharper disable once PossibleNullReferenceException
            exCaught.TableName.ShouldEqual("dbo.Parent");
        }
예제 #4
0
        private void btn_add_Click(object sender, RoutedEventArgs e)
        {
            ServiceClient client = new ServiceClient();
            ParentRecord  record = new ParentRecord();

            record.Name = tb_name.Text;

            try
            {
                record.Birth_day = Convert.ToDateTime(tb_birth_day.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Invalid date");
                return;
            }

            try
            {
                client.InsertParent(token, record);
                MessageBox.Show("Success!");
            }
            catch (FaultException <ServiceData> sd)
            {
                Logger.Error("[Service] " + sd.Message);
                MessageBox.Show(sd.Message);
            }
        }
예제 #5
0
        internal Dictionary <string, string> GetProperties()
        {
            var properties = new Dictionary <string, string>();

            if (ParentRecord != default(Guid))
            {
                properties.Add("parentid", ParentRecord.ToString());
            }
            if (StartTime.HasValue)
            {
                properties.Add("starttime", StartTime.ToString());
            }
            if (FinishTime.HasValue)
            {
                properties.Add("finishtime", FinishTime.ToString());
            }
            if (Progress.HasValue)
            {
                properties.Add("progress", Progress.ToString());
            }
            if (Status.HasValue)
            {
                properties.Add("state", Status.ToString());
            }
            if (Result.HasValue)
            {
                properties.Add("result", Result.ToString());
            }
            return(properties);
        }
        private DomainModel.Models.IncidentReport.PosIncidentReport SaveIncidentReportDetails(DomainModel.Models.IncidentReport.PosIncidentReport incidentReportInfo, WorkFlowDetail activityWorkFlow, string comment, UserDetail userDetail)
        {
            try
            {
                if (incidentReportInfo != null)
                {
                    ParentRecord parentRecord = new ParentRecord();
                    parentRecord.BranchId          = incidentReportInfo.BranchId;
                    parentRecord.CreatedDateTime   = DateTime.UtcNow;
                    parentRecord.InitiationComment = comment;
                    parentRecord.InitiationDate    = DateTime.UtcNow;
                    parentRecord.ModificationDate  = DateTime.UtcNow;
                    parentRecord.InitiatorId       = userDetail.UserId;
                    parentRecord.ModifiedUserId    = userDetail.UserId;
                    parentRecord.WorkFlowId        = activityWorkFlow.Id;
                    _parentRecordContext.Add(parentRecord);
                    _parentRecordContext.SaveChanges();

                    if (parentRecord.Id != 0)
                    {
                        WorkFlowLog workFlowLog = new WorkFlowLog();
                        workFlowLog.Comments        = comment;
                        workFlowLog.CreatedDateTime = DateTime.UtcNow;
                        workFlowLog.RecordId        = parentRecord.Id;
                        workFlowLog.RoleId          = userDetail.RoleId;
                        workFlowLog.UserId          = userDetail.UserId;
                        workFlowLog.WorkFlowId      = activityWorkFlow.Id;
                        workFlowLog.Action          = StringConstants.InitiateAction;
                        workFlowLog.Stage           = (userDetail.RoleName) + " " + (activityWorkFlow.Activity != null ? activityWorkFlow.Activity.Name : "");
                        _workFLowLogContext.Add(workFlowLog);
                        _workFLowLogContext.SaveChanges();

                        if (workFlowLog.Id != 0)
                        {
                            incidentReportInfo.IsProcess        = false;
                            incidentReportInfo.RecordId         = parentRecord.Id;
                            incidentReportInfo.ModifiedDateTime = DateTime.UtcNow;
                            _posIncidentReportDataRepository.Update(incidentReportInfo);
                            _posIncidentReportDataRepository.SaveChanges();
                        }
                    }
                    return(incidentReportInfo);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }
예제 #7
0
        public void InsertParent(string token, ParentRecord record)
        {
            bool ok;

            try
            {
                ok = Identification(token);
            }
            catch (DatabaseConnectionException e)
            {
                ServiceData sd = new ServiceData();
                sd.ErrorMessage = e.Message;
                throw new FaultException <ServiceData>(sd, new FaultReason(sd.ErrorMessage));
            }
            catch (DatabaseCommandTextException e)
            {
                ServiceData sd = new ServiceData();
                sd.ErrorMessage = e.Message;
                throw new FaultException <ServiceData>(sd, new FaultReason(sd.ErrorMessage));
            }
            catch (DatabaseParameterException e)
            {
                ServiceData sd = new ServiceData();
                sd.ErrorMessage = e.Message;
                throw new FaultException <ServiceData>(sd, new FaultReason(sd.ErrorMessage));
            }

            if (ok)
            {
                try
                {
                    parentManager.InsertParent(record);
                }
                catch (DatabaseConnectionException e)
                {
                    ServiceData sd = new ServiceData();
                    sd.ErrorMessage = e.Message;
                    throw new FaultException <ServiceData>(sd, new FaultReason(sd.ErrorMessage));
                }
                catch (DatabaseCommandTextException e)
                {
                    ServiceData sd = new ServiceData();
                    sd.ErrorMessage = e.Message;
                    throw new FaultException <ServiceData>(sd, new FaultReason(sd.ErrorMessage));
                }
                catch (DatabaseParameterException e)
                {
                    ServiceData sd = new ServiceData();
                    sd.ErrorMessage = e.Message;
                    throw new FaultException <ServiceData>(sd, new FaultReason(sd.ErrorMessage));
                }
            }
        }
 /// <summary>
 /// This method used for insert parent Recored and return Primary key. -An
 /// </summary>
 /// <param name="parentRecord">TypeId,StatusId,BranchId,InitiatorId,InitiationComment,ModifiedUserId,ModifiedUserId,ModificationDate</param>
 /// <returns></returns>
 public int AddParentRecords(ParentRecord parentRecord)
 {
     try
     {
         _iParentRecordContext.Add(parentRecord);
         _iParentRecordContext.SaveChanges();
         return(parentRecord.Id);
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
예제 #9
0
        public ParentRecord SelectParent(int id)
        {
            SqlCommand command = new SqlCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = @"SELECT * 
                                    FROM Parents 
                                    WHERE id = @id";

            SqlParameter pId = new SqlParameter();

            pId.ParameterName = "@id";
            pId.Value         = id;
            pId.Direction     = System.Data.ParameterDirection.Input;
            pId.DbType        = System.Data.DbType.Int64;
            command.Parameters.Add(pId);

            try { command.Connection = getConnection(); }
            catch (Exception)
            {
                throw new DatabaseConnectionException();
            }

            SqlDataReader reader;

            try { reader = command.ExecuteReader(); }
            catch (Exception)
            {
                throw new DatabaseCommandTextException();
            }

            ParentRecord loadedRecord = new ParentRecord();

            try
            {
                if (reader.Read())
                {
                    loadedRecord           = new ParentRecord();
                    loadedRecord.Id        = int.Parse(reader["id"].ToString());
                    loadedRecord.Name      = reader["name"].ToString();
                    loadedRecord.Birth_day = DateTime.Parse(reader["birth_day"].ToString());
                }
            }
            catch (Exception)
            {
                throw new DatabaseParameterException();
            }

            return(loadedRecord);
        }
예제 #10
0
        public int SelectParentId(string name)
        {
            SqlCommand command = new SqlCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = @"SELECT * 
                                    FROM Parents 
                                    WHERE name = @name";

            SqlParameter pName = new SqlParameter();

            pName.ParameterName = "@name";
            pName.Value         = name;
            pName.Direction     = System.Data.ParameterDirection.Input;
            pName.DbType        = System.Data.DbType.String;
            command.Parameters.Add(pName);

            try { command.Connection = getConnection(); }
            catch (Exception)
            {
                throw new DatabaseConnectionException();
            }

            SqlDataReader reader;

            try { reader = command.ExecuteReader(); }
            catch (Exception)
            {
                throw new DatabaseCommandTextException();
            }

            ParentRecord loadedRecord = new ParentRecord();

            try
            {
                if (reader.Read())
                {
                    return(int.Parse(reader["id"].ToString()));
                }
            }
            catch (Exception)
            {
                throw new DatabaseParameterException();
            }

            return(-1);
        }
예제 #11
0
        public List <ParentRecord> SelectAll()
        {
            SqlCommand command = new SqlCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = @"SELECT * 
                                    FROM Parents";

            try { command.Connection = getConnection(); }
            catch (Exception)
            {
                throw new DatabaseConnectionException();
            }

            SqlDataReader reader;

            try { reader = command.ExecuteReader(); }
            catch (Exception)
            {
                throw new DatabaseCommandTextException();
            }

            List <ParentRecord> records = new List <ParentRecord>();

            try
            {
                while (reader.Read())
                {
                    ParentRecord record = new ParentRecord();
                    record.Id        = int.Parse(reader["id"].ToString());
                    record.Name      = reader["name"].ToString();
                    record.Birth_day = DateTime.Parse(reader["birth_day"].ToString());
                    records.Add(record);
                }
            }
            catch (Exception)
            {
                throw new DatabaseParameterException();
            }

            return(records);
        }
예제 #12
0
        public void InsertParent(ParentRecord record)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "InsertParent";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@name", record.Name);
            cmd.Parameters.AddWithValue("@birth_day", record.Birth_day);

            try { cmd.Connection = getConnection(); }
            catch (Exception)
            {
                throw new DatabaseConnectionException();
            }

            try { cmd.ExecuteNonQuery(); }
            catch (Exception)
            {
                throw new DatabaseCommandTextException();
            }
        }
        public IHttpActionResult ResetIncidnetReport(int cashierId)
        {
            try
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    ManageIncidentReportAC       manageIncidentReportAC    = new ManageIncidentReportAC();
                    List <CashierIncidentReport> cashierIncidentReportList = _incidentReportRepository.GetCashierIncidentListByCashierId(cashierId);

                    if (cashierIncidentReportList.Count > 0 && cashierIncidentReportList[cashierIncidentReportList.Count - 1] != null)
                    {
                        var userDetial = _iUserDetailReport.GetUserDetailByUserName(HttpContext.Current.User.Identity.Name);
                        if (userDetial != null)
                        {
                            if (cashierIncidentReportList[cashierIncidentReportList.Count - 1].IsResetRequest == true)
                            {
                                var workFlowLog = _iParentRecordsRepository.GetLastWorkFlowDetaiByRecordId(Convert.ToInt32(cashierIncidentReportList[cashierIncidentReportList.Count - 1].RecordId));
                                if (workFlowLog != null)
                                {
                                    if (workFlowLog.WorkFlowDetail.IsApproval && workFlowLog.WorkFlowDetail.IsParentAction && workFlowLog.WorkFlowDetail.AssignedId == userDetial.RoleId)
                                    {
                                        manageIncidentReportAC.IsApproval = true;
                                    }
                                    return(Ok(new { result = manageIncidentReportAC }));
                                }
                            }
                            else
                            {
                                List <WorkFlowDetail> listOfWorkFlowDetail = _iParentRecordsRepository.GetWorkFlowDetailListByParent(StringConstants.IncidentReportParamenter, userDetial.Branch.CompanyId);
                                if (listOfWorkFlowDetail.Any())
                                {
                                    var activityWorkFlow = listOfWorkFlowDetail.FirstOrDefault(x => x.InitiatorId == userDetial.RoleId && x.IsParentAction);
                                    if (activityWorkFlow != null)
                                    {
                                        ParentRecord parentRecord = new ParentRecord();
                                        parentRecord.BranchId          = cashierIncidentReportList[0].UserDetail.BranchId;
                                        parentRecord.CreatedDateTime   = DateTime.UtcNow;
                                        parentRecord.WorkFlowId        = activityWorkFlow.Id;
                                        parentRecord.ModificationDate  = parentRecord.CreatedDateTime;
                                        parentRecord.InitiationDate    = parentRecord.ModificationDate;
                                        parentRecord.ModifiedUserId    = userDetial.UserId;
                                        parentRecord.InitiatorId       = parentRecord.ModifiedUserId;
                                        parentRecord.InitiationComment = "Reset Incident Report By" + userDetial.RoleName;
                                        int recordId = _iParentRecordsRepository.AddParentRecords(parentRecord);
                                        if (recordId != 0)
                                        {
                                            WorkFlowLog workFLowLogDetail = new WorkFlowLog();
                                            workFLowLogDetail.Action          = "Reset Incident Report";
                                            workFLowLogDetail.Stage           = (activityWorkFlow.Activity != null ? activityWorkFlow.Activity.Name : "") + " By" + (MerchantContext.UserDetails != null ? MerchantContext.UserDetails.RoleName : "");
                                            workFLowLogDetail.UserId          = userDetial.UserId;
                                            workFLowLogDetail.WorkFlowId      = activityWorkFlow.Id;
                                            workFLowLogDetail.RoleId          = userDetial.RoleId;
                                            workFLowLogDetail.CreatedDateTime = DateTime.UtcNow;
                                            workFLowLogDetail.RecordId        = recordId;
                                            workFLowLogDetail.Comments        = "Reset Incident Report By" + userDetial.RoleName;
                                            int workFlowId = _iParentRecordsRepository.AddWorkFlowLogs(workFLowLogDetail);
                                            if (workFlowId != 0)
                                            {
                                                foreach (var cashierIncidentReport in cashierIncidentReportList)
                                                {
                                                    cashierIncidentReport.RecordId         = recordId;
                                                    cashierIncidentReport.ModifiedDateTime = DateTime.UtcNow;
                                                    if (activityWorkFlow.IsClosed)
                                                    {
                                                        cashierIncidentReport.IsResetRequest   = true;
                                                        cashierIncidentReport.IsRefreshRequset = true;
                                                    }
                                                    else
                                                    {
                                                        manageIncidentReportAC.IsApproveByBranchSupervisor = true;
                                                        cashierIncidentReport.IsResetRequest = true;
                                                    }
                                                    _incidentReportRepository.UpdateCashierIncidentReportByCashier(cashierIncidentReport);
                                                }
                                                manageIncidentReportAC.IsAddParentRecord = true;
                                                return(Ok(new { result = manageIncidentReportAC }));
                                            }
                                        }
                                    }
                                }
                                return(Ok(new { result = "IsNotWorkFlow" }));
                            }
                        }
                        return(Ok(new { result = false }));
                    }

                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }
 public int InsertParent(ParentRecord record, bool identity)
 {
     Operation(ctx => ctx.Insert(record, identity));
     return(record.Id);
 }