Exemplo n.º 1
0
        private NotificationMsgVm PopulateNotificationMsgVmFromIDataReader(IDataReader reader)
        {
            NotificationMsgVm notifi = new NotificationMsgVm();

            if (reader["NotificationMsgID"] != DBNull.Value)
            {
                notifi.NotificationMsgID = (int)reader["NotificationMsgID"];
            }
            if (reader["NotificationTypeID"] != DBNull.Value)
            {
                notifi.NotificationTypeID = (int)reader["NotificationTypeID"];
            }
            if (reader["ObjectID"] != DBNull.Value)
            {
                notifi.ObjectID = (int)reader["ObjectID"];
            }

            if (reader["NotificationTitle"] != DBNull.Value)
            {
                notifi.NotificationTitle = (string)reader["NotificationTitle"];
            }
            if (reader["NotificationMsg"] != DBNull.Value)
            {
                notifi.NotificationMsg = (string)reader["NotificationMsg"];
            }

            if (reader["CreatedDate"] != DBNull.Value)
            {
                notifi.CreatedDate = (DateTime)reader["CreatedDate"];
            }

            return(notifi);
        }
Exemplo n.º 2
0
 public void Create_Notification(NotificationMsgVm notifi)
 {
     using (SqlConnection myConnection = GetSqlConnection())
     {
         bool       result    = false;
         SqlCommand myCommand = new SqlCommand("Notifi_Actions", myConnection);
         myCommand.CommandType = CommandType.StoredProcedure;
         // Set the parameters
         myCommand.Parameters.AddWithValue("@Action", 1);
         myCommand.Parameters.AddWithValue("@NotificationTypeID", notifi.NotificationTypeID);
         myCommand.Parameters.AddWithValue("@ObjectID", notifi.ObjectID);
         myCommand.Parameters.AddWithValue("@NotificationMsg", notifi.NotificationMsg);
         // Execute the command
         myConnection.Open();
         result = myCommand.ExecuteNonQuery() > 0;
         myConnection.Close();
     }
 }
Exemplo n.º 3
0
        public static string AddEditOperation(OperationVm operationVm, out int operId)
        {
            string                    isSaved     = "true";
            int                       operationId = operationVm.OperationId;
            OperationsEntities        db          = new OperationsEntities();
            Operation                 operationDb;
            List <OperationContainer> operationContListDb;
            // notifications
            NotificationMsgVm notifi = new NotificationMsgVm();

            if (operationId == 0)
            {
                operationDb         = new Operation();
                operationContListDb = new List <OperationContainer>();
            }
            else
            {
                operationDb = db.Operations.Include("OperationContainers")
                              .Where(x => x.OperationId == operationId).FirstOrDefault();
                if (operationDb.StatusId > 2)
                {
                    operId  = operationDb.OperationId;
                    isSaved = "false .. Cann't update operation is not open ";
                    return(isSaved);
                }
                operationContListDb = operationDb.OperationContainers.ToList();

                //Get quotContainers Ids sent from the screen
                List <long> containerVmIds = operationVm.OperationContainers.Select(x => x.OperConId).ToList();
                var         containerDel   = operationContListDb.Where(x => !containerVmIds.Contains(x.OperConId)).ToList();

                foreach (var item in containerDel)
                {
                    db.OperationContainers.Remove(item);
                }
            }

            Mapper.CreateMap <OperationVm, Operation>().IgnoreAllNonExisting();
            // .ForMember(x => x.OperationContainers, v=> v.Ignore());
            Mapper.CreateMap <OperationContainerVm, OperationContainer>().IgnoreAllNonExisting();
            Mapper.Map(operationVm, operationDb);

            bool updateHB = false;

            if (operationId == 0)
            {
                //Generate code at save event
                if (operationDb.OrderFrom == 1)
                {
                    operationDb.OperationCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.Export, true);
                }
                else
                {
                    operationDb.OperationCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.Import, true);
                }

                db.Operations.Add(operationDb);
                //update quotation status if any
                int?quoteId = operationVm.QuoteId;
                if (quoteId != null)
                {
                    //status = 2 -- opened
                    Quotation quoteToUpdate = db.Quotations.Where(x => x.QuoteId == quoteId).FirstOrDefault();
                    quoteToUpdate.StatusId = 2;
                }

                notifi.NotificationTypeID = (operationDb.OrderFrom == 1) ? 1 : 3;
                notifi.ObjectID           = -1;
            }
            else
            {
                List <HouseBillListVm> hbList = HouseBillHelper.GetHBList(operationId, operationDb.OrderFrom);
                if (hbList.Count == 1)
                {
                    if (!operationDb.IsConsolidation)
                    {
                        HouseBill hb = db.HouseBills.Where(x => x.OperationId == operationDb.OperationId).FirstOrDefault();
                        hb.CBM = operationDb.CBM;
                        hb.GoodsDescription     = operationDb.GoodsDescription;
                        hb.GrossWeight          = operationDb.GrossWeight;
                        hb.NetWeight            = operationDb.NetWeight;
                        hb.NumberOfPackages     = operationDb.NumberOfPackages;
                        hb.CollectedFreightCost = operationDb.FreightCostAmount;
                        hb.CollectedThcCost     = operationDb.ThcCostAmount;



                        // hb.ShipperId = operationDb.ShipperId;
                        //  hb.ConsigneeId = operationDb.ConsigneeId;
                        // hb.NotifierId = operationDb.NotifierId;
                        //  hb.NotifierAsConsignee = operationDb.NotifierAsConsignee;
                        //  hb.AgentId = operationDb.AgentId;

                        hb.FromPortId = operationDb.FromPortId;
                        hb.ToPortId   = operationDb.ToPortId;
                    }
                }
            }
            operId = 0;
            try
            {
                db.SaveChanges();
                operId = operationDb.OperationId;
                if (notifi.ObjectID == -1)
                {
                    notifi.ObjectID        = operId;
                    notifi.NotificationMsg = " New " + (operationDb.OrderFrom == 1 ? "Export " : "Import ") + " Operation Code: " + operationDb.OperationCode;
                    NotificationHelper.Create_Notification(notifi);
                }

                //update hb
                if (updateHB)
                {
                }
            }
            catch (DbEntityValidationException e)
            {
                isSaved = "false " + e.Message;
            }
            catch (Exception e)
            {
                isSaved = "false " + e.Message;
            }

            return(isSaved);
        }
Exemplo n.º 4
0
 public static void Create_Notification(NotificationMsgVm notifi)
 {
     NotificationSql.Instance.Create_Notification(notifi);
 }